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