diff --git a/commands/list.go b/commands/list.go index 747f43c..569388b 100644 --- a/commands/list.go +++ b/commands/list.go @@ -79,6 +79,12 @@ func newListCommand(cnf *config.Config) *cobra.Command { list.AddCommand(&appConfigValidateCommand) } + regionsListCommand := innerRegionsListCommand(cnf) + + if !list.DescribesNamespace() || list.Namespace == regionsListCommand.Name.Namespace { + list.AddCommand(®ionsListCommand) + } + format := viper.GetString("format") raw := viper.GetBool("raw") diff --git a/commands/list_models.go b/commands/list_models.go index 7111b6f..0124e83 100644 --- a/commands/list_models.go +++ b/commands/list_models.go @@ -118,6 +118,62 @@ func innerAppConfigValidateCommand(cnf *config.Config) Command { } } +type Region struct { + Label string `json:"label"` + Zone string `json:"zone"` +} + +func innerRegionsListCommand(cnf *config.Config) Command { + noInteractionOption := NoInteractionOption(cnf) + + return Command{ + Name: CommandName{ + Namespace: "region", + Command: "list", + }, + Usage: []string{ + cnf.Application.Executable + " region:list", + }, + Aliases: []string{ + "regions", + }, + Description: "List available regions", + Help: "", + Examples: []Example{ + { + Commandline: "", + Description: "List available regions with all their informations (provider, location...)", + }, + }, + Definition: Definition{ + Arguments: &orderedmap.OrderedMap[string, Argument]{}, + Options: orderedmap.New[string, Option](orderedmap.WithInitialData[string, Option]( + orderedmap.Pair[string, Option]{ + Key: HelpOption.GetName(), + Value: HelpOption, + }, + orderedmap.Pair[string, Option]{ + Key: VerboseOption.GetName(), + Value: VerboseOption, + }, + orderedmap.Pair[string, Option]{ + Key: VersionOption.GetName(), + Value: VersionOption, + }, + orderedmap.Pair[string, Option]{ + Key: YesOption.GetName(), + Value: YesOption, + }, + orderedmap.Pair[string, Option]{ + Key: noInteractionOption.GetName(), + Value: noInteractionOption, + }, + )), + }, + Hidden: false, + } +} + type List struct { Application Application `json:"application"` Commands []*Command `json:"commands"` diff --git a/commands/root.go b/commands/root.go index be74347..5b748eb 100644 --- a/commands/root.go +++ b/commands/root.go @@ -131,6 +131,13 @@ func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob fmt.Println(internalCmd.HelpPage(cnf)) }) + regionsListCmd := commands.NewRegionsCmd(assets) + regionsListCmd.Use = "regions:list" + regionsListCmd.SetHelpFunc(func(_ *cobra.Command, args []string) { + internalCmd := innerRegionsListCommand(cnf) + fmt.Println(internalCmd.HelpPage(cnf)) + }) + // Add subcommands. cmd.AddCommand( newCompletionCommand(cnf), @@ -138,6 +145,7 @@ func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob newListCommand(cnf), projectInitCmd, validateCmd, + regionsList versionCommand, )