Skip to content

Commit

Permalink
clusterctl: add command groups
Browse files Browse the repository at this point in the history
  • Loading branch information
oscr committed Dec 18, 2022
1 parent 333341b commit 47ac8f9
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 31 deletions.
7 changes: 4 additions & 3 deletions cmd/clusterctl/cmd/alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
)

var alphaCmd = &cobra.Command{
Use: "alpha",
Short: "Commands for features in alpha",
Long: `These commands correspond to alpha features in clusterctl.`,
Use: "alpha",
GroupID: groupOther,
Short: "Commands for features in alpha",
Long: `These commands correspond to alpha features in clusterctl.`,
}

func init() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterctl/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ type backupOptions struct {
var buo = &backupOptions{}

var backupCmd = &cobra.Command{
Use: "backup",
Short: "Backup Cluster API objects and all dependencies from a management cluster",
Use: "backup",
GroupID: groupManagement,
Short: "Backup Cluster API objects and all dependencies from a management cluster",
Long: LongDesc(`
Backup Cluster API objects and all dependencies from a management cluster.`),

Expand Down
1 change: 1 addition & 0 deletions cmd/clusterctl/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var (

completionCmd = &cobra.Command{
Use: "completion [bash|zsh]",
GroupID: groupOther,
Short: "Output shell completion code for the specified shell (bash or zsh)",
Long: LongDesc(completionLong),
Example: completionExample,
Expand Down
7 changes: 4 additions & 3 deletions cmd/clusterctl/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
)

var configCmd = &cobra.Command{
Use: "config",
Short: "Display clusterctl configuration",
Long: `Display clusterctl configuration.`,
Use: "config",
GroupID: groupOther,
Short: "Display clusterctl configuration",
Long: `Display clusterctl configuration.`,
}

func init() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterctl/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ type deleteOptions struct {
var dd = &deleteOptions{}

var deleteCmd = &cobra.Command{
Use: "delete [providers]",
Short: "Delete one or more providers from the management cluster",
Use: "delete [providers]",
GroupID: groupManagement,
Short: "Delete one or more providers from the management cluster",
Long: LongDesc(`
Delete one or more providers from the management cluster.`),

Expand Down
7 changes: 4 additions & 3 deletions cmd/clusterctl/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
)

var describeCmd = &cobra.Command{
Use: "describe",
Short: "Describe workload clusters",
Long: `Describe the status of workload clusters.`,
Use: "describe",
GroupID: groupManagement,
Short: "Describe workload clusters",
Long: `Describe the status of workload clusters.`,
}

func init() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/clusterctl/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
)

var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate yaml using clusterctl yaml processor",
Long: `Generate yaml using clusterctl yaml processor.`,
Use: "generate",
GroupID: groupManagement,
Short: "Generate yaml using clusterctl yaml processor",
Long: `Generate yaml using clusterctl yaml processor.`,
}

func init() {
Expand Down
7 changes: 4 additions & 3 deletions cmd/clusterctl/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
)

var getCmd = &cobra.Command{
Use: "get",
Short: "Get info from a management or workload cluster",
Long: `Get info from a management or workload cluster`,
Use: "get",
GroupID: groupManagement,
Short: "Get info from a management or workload cluster",
Long: `Get info from a management or workload cluster`,
}

func init() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterctl/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ type initOptions struct {
var initOpts = &initOptions{}

var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize a management cluster",
Use: "init",
GroupID: groupManagement,
Short: "Initialize a management cluster",
Long: LongDesc(`
Initialize a management cluster.
Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterctl/cmd/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type moveOptions struct {
var mo = &moveOptions{}

var moveCmd = &cobra.Command{
Use: "move",
Short: "Move Cluster API objects and all dependencies between management clusters",
Use: "move",
GroupID: groupManagement,
Short: "Move Cluster API objects and all dependencies between management clusters",
Long: LongDesc(`
Move Cluster API objects and all dependencies between management clusters.
Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterctl/cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ type restoreOptions struct {
var ro = &restoreOptions{}

var restoreCmd = &cobra.Command{
Use: "restore",
Short: "Restore Cluster API objects from file by glob. Object files are searched in config directory",
Use: "restore",
GroupID: groupManagement,
Short: "Restore Cluster API objects from file by glob. Object files are searched in config directory",
Long: LongDesc(`
Restore Cluster API objects from file by glob. Object files are searched in the default config directory
or in the provided directory.`),
Expand Down
18 changes: 18 additions & 0 deletions cmd/clusterctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type stackTracer interface {
StackTrace() errors.StackTrace
}

const (
groupManagement = "group-management"
groupOther = "group-other"
)

var (
cfgFile string
verbosity *int
Expand Down Expand Up @@ -118,6 +123,19 @@ func init() {
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "",
"Path to clusterctl configuration (default is `$HOME/.cluster-api/clusterctl.yaml`) or to a remote location (i.e. https://example.com/clusterctl.yaml)")

RootCmd.AddGroup(
&cobra.Group{
ID: groupManagement,
Title: "Cluster Management Commands:",
},
&cobra.Group{
ID: groupOther,
Title: "Other commands:",
})

RootCmd.SetHelpCommandGroupID(groupOther)
RootCmd.SetCompletionCommandGroupID(groupOther)

cobra.OnInitialize(initConfig, registerCompletionFuncForCommonFlags)
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/clusterctl/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
)

var upgradeCmd = &cobra.Command{
Use: "upgrade",
Short: "Upgrade core and provider components in a management cluster",
Args: cobra.NoArgs,
Use: "upgrade",
GroupID: groupManagement,
Short: "Upgrade core and provider components in a management cluster",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Expand Down
7 changes: 4 additions & 3 deletions cmd/clusterctl/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type versionOptions struct {
var vo = &versionOptions{}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print clusterctl version",
Args: cobra.NoArgs,
Use: "version",
GroupID: groupOther,
Short: "Print clusterctl version",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runVersion()
},
Expand Down

0 comments on commit 47ac8f9

Please sign in to comment.