|
15 | 15 | package main |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "context" |
18 | 19 | "errors" |
19 | 20 | "fmt" |
20 | 21 | "maps" |
21 | 22 | "os" |
22 | 23 | "strings" |
23 | 24 |
|
| 25 | + "github.com/charmbracelet/huh" |
24 | 26 | "github.com/joho/godotenv" |
25 | 27 | "github.com/twitchtv/twirp" |
26 | 28 | "github.com/urfave/cli/v3" |
@@ -217,21 +219,27 @@ func parseKeyValuePairs(c *cli.Command, flag string) (map[string]string, error) |
217 | 219 | } |
218 | 220 |
|
219 | 221 | type loadParams struct { |
220 | | - requireURL bool |
| 222 | + requireURL bool |
| 223 | + confirmProject bool |
221 | 224 | } |
222 | 225 |
|
223 | 226 | type loadOption func(*loadParams) |
224 | 227 |
|
225 | | -var ignoreURL = func(p *loadParams) { |
226 | | - p.requireURL = false |
227 | | -} |
| 228 | +var ( |
| 229 | + ignoreURL = func(p *loadParams) { |
| 230 | + p.requireURL = false |
| 231 | + } |
| 232 | + confirmProject = func(p *loadParams) { |
| 233 | + p.confirmProject = true |
| 234 | + } |
| 235 | +) |
228 | 236 |
|
229 | 237 | // attempt to load connection config, it'll prioritize |
230 | 238 | // 1. command line flags (or env var) |
231 | 239 | // 2. config file (by default, livekit.toml) |
232 | 240 | // 3. default project config |
233 | 241 | func loadProjectDetails(c *cli.Command, opts ...loadOption) (*config.ProjectConfig, error) { |
234 | | - p := loadParams{requireURL: true} |
| 242 | + p := loadParams{requireURL: true, confirmProject: false} |
235 | 243 | for _, opt := range opts { |
236 | 244 | opt(&p) |
237 | 245 | } |
@@ -327,9 +335,31 @@ func loadProjectDetails(c *cli.Command, opts ...loadOption) (*config.ProjectConf |
327 | 335 | // load default project |
328 | 336 | dp, err := config.LoadDefaultProject() |
329 | 337 | if err == nil { |
330 | | - if !c.Bool("silent") { |
331 | | - fmt.Println("Using default project [" + util.Theme.Focused.Title.Render(dp.Name) + "]") |
332 | | - logDetails(c, dp) |
| 338 | + if p.confirmProject { |
| 339 | + if dp != nil && len(cliConfig.Projects) > 1 && !c.Bool("silent") { |
| 340 | + useDefault := true |
| 341 | + if err := huh.NewForm(huh.NewGroup(huh.NewConfirm(). |
| 342 | + Title(fmt.Sprintf("Use project [%s] (%s) to create agent?", dp.Name, dp.URL)). |
| 343 | + Value(&useDefault). |
| 344 | + Negative("Select another"). |
| 345 | + Inline(false). |
| 346 | + WithTheme(util.Theme))). |
| 347 | + Run(); err != nil { |
| 348 | + return nil, fmt.Errorf("failed to confirm project: %w", err) |
| 349 | + } |
| 350 | + if !useDefault { |
| 351 | + if _, err = selectProject(context.Background(), c); err != nil { |
| 352 | + return nil, err |
| 353 | + } |
| 354 | + fmt.Printf("Using project [%s]\n", util.Accented(project.Name)) |
| 355 | + return project, nil |
| 356 | + } |
| 357 | + } |
| 358 | + } else { |
| 359 | + if !c.Bool("silent") { |
| 360 | + fmt.Println("Using default project [" + util.Theme.Focused.Title.Render(dp.Name) + "]") |
| 361 | + logDetails(c, dp) |
| 362 | + } |
333 | 363 | } |
334 | 364 | return dp, nil |
335 | 365 | } |
|
0 commit comments