Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP New regions:list command #130

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(&regionsListCommand)
}

format := viper.GetString("format")
raw := viper.GetBool("raw")

Expand Down
56 changes: 56 additions & 0 deletions commands/list_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,62 @@ func innerAppConfigValidateCommand(cnf *config.Config) Command {
}
}

type Region struct {
Label string `json:"label"`
Zone string `json:"zone"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem with this is that it would depend on #82 or similar (because the /regions API requires authentication)


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"`
Expand Down
8 changes: 8 additions & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,21 @@ 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),
newHelpCommand(cnf),
newListCommand(cnf),
projectInitCmd,
validateCmd,
regionsList
versionCommand,
)

Expand Down