()
| 88 | } |
| 89 | |
| 90 | func initConfigInteractive() { |
| 91 | items := []list.Item{ |
| 92 | configItem{title: ".lunacfg", desc: "Project configuration (current directory)", value: "project"}, |
| 93 | configItem{title: ".lunarc", desc: "Global configuration (home directory)", value: "global"}, |
| 94 | configItem{title: "Both files", desc: "Create both configurations", value: "both"}, |
| 95 | configItem{title: "Exit", desc: "Exit without creating any files", value: "exit"}, |
| 96 | } |
| 97 | |
| 98 | l := list.New(items, list.NewDefaultDelegate(), 60, 14) |
| 99 | l.Title = "🗁 Select configuration files to create" |
| 100 | l.SetShowStatusBar(false) |
| 101 | l.SetFilteringEnabled(false) |
| 102 | |
| 103 | m := model{list: l} |
| 104 | p := tea.NewProgram(m, tea.WithAltScreen()) |
| 105 | |
| 106 | finalModel, err := p.Run() |
| 107 | if err != nil { |
| 108 | fmt.Printf("Error running config menu: %v\n", err) |
| 109 | return |
| 110 | } |
| 111 | |
| 112 | m = finalModel.(model) |
| 113 | |
| 114 | if contains(m.selected, "exit") || len(m.selected) == 0 { |
| 115 | fmt.Println("🚪 Exit without creating any files") |
| 116 | return |
| 117 | } |
| 118 | |
| 119 | if contains(m.selected, "both") { |
| 120 | m.selected = []string{"project", "global"} |
| 121 | } |
| 122 | |
| 123 | createSelectedConfigs(m.selected) |
| 124 | |
| 125 | for _, sel := range m.selected { |
| 126 | switch sel { |
| 127 | case "project": |
| 128 | apiKey := askForAPIKey("project") |
| 129 | if apiKey != "" { |
| 130 | cfg := LoadProjectConfig() |
| 131 | cfg.ApiKey = apiKey |
| 132 | SaveProjectConfig(cfg) |
| 133 | } |
| 134 | case "global": |
| 135 | apiKey := askForAPIKey("global") |
| 136 | if apiKey != "" { |
| 137 | cfg := LoadGlobalConfig() |
| 138 | cfg.ApiKey = apiKey |
| 139 | SaveGlobalConfig(cfg) |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | type model struct { |
| 146 | list list.Model |
no test coverage detected