diff --git a/cmd/lk/agent.go b/cmd/lk/agent.go index 935971ed..e5ed38fd 100644 --- a/cmd/lk/agent.go +++ b/cmd/lk/agent.go @@ -83,11 +83,10 @@ var ( Required: false, } - regionFlag = &cli.StringSliceFlag{ - Name: "regions", - Usage: "Region(s) to deploy the agent to. If unset, will deploy to the nearest region.", + regionFlag = &cli.StringFlag{ + Name: "region", + Usage: "Region to deploy the agent to. If unset, will deploy to the nearest region.", Required: false, - Hidden: true, } skipSDKCheckFlag = &cli.BoolFlag{ @@ -141,7 +140,9 @@ var ( }, }}, }}, - Flags: []cli.Flag{}, + Flags: []cli.Flag{ + regionFlag, + }, ArgsUsage: "[AGENT-NAME]", DisableSliceFlagSeparator: true, }, @@ -554,7 +555,31 @@ func createAgent(ctx context.Context, cmd *cli.Command) error { } } - regions := cmd.StringSlice("regions") + region := cmd.String("region") + if region == "" { + availableRegionsStr, ok := settingsMap["available_regions"] + if ok && availableRegionsStr != "" { + regionOptions := strings.Split(availableRegionsStr, ",") + for i, r := range regionOptions { + regionOptions[i] = strings.TrimSpace(r) + } + + if err := huh.NewSelect[string](). + Title("Select region for agent deployment"). + Options(huh.NewOptions(regionOptions...)...). + Value(®ion). + WithTheme(util.Theme). + Run(); err != nil { + return err + } + } else { + // we shouldn't ever get here, but if we do, just default to us-east + logger.Debugw("no available regions found, defaulting to us-east. please contact LiveKit support if this is unexpected.") + region = "us-east" + } + } + + regions := []string{region} excludeFiles := []string{fmt.Sprintf("**/%s", config.LiveKitTOMLFile)} resp, err := agentsClient.CreateAgent(ctx, os.DirFS(workingDir), secrets, regions, excludeFiles) if err != nil {