MCPcopy Create free account
hub / github.com/LunaSource/Luna / initConfigInteractive

Function initConfigInteractive

config/config.go:90–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88}
89
90func 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
145type model struct {
146 list list.Model

Callers 1

ManageConfigFunction · 0.85

Calls 7

containsFunction · 0.85
createSelectedConfigsFunction · 0.85
askForAPIKeyFunction · 0.85
LoadProjectConfigFunction · 0.85
SaveProjectConfigFunction · 0.85
LoadGlobalConfigFunction · 0.85
SaveGlobalConfigFunction · 0.85

Tested by

no test coverage detected