Skip to content

Commit

Permalink
Merge pull request #1576 from stgraber/main
Browse files Browse the repository at this point in the history
incusd/main_cluster: Tweak to have help refer to correct command name
  • Loading branch information
hallyn authored Jan 15, 2025
2 parents e35b354 + 8dc5979 commit 955e6fa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/incus/admin_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ You can invoke it through "incusd cluster".`))
os.Exit(1)
}

_ = doExec(path, append([]string{"incusd", "cluster"}, args...), env)
_ = doExec(path, append([]string{"incusd", "admin", "cluster"}, args...), env)
}
10 changes: 9 additions & 1 deletion cmd/incusd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func main() {
// Workaround for main command
app.Args = cobra.ArbitraryArgs

// Workaround for being called through "incus admin cluster".
if len(os.Args) >= 3 && os.Args[0] == "incusd" && os.Args[1] == "admin" && os.Args[2] == "cluster" {
app.Use = "incus"
}

// Global flags
globalCmd := cmdGlobal{cmd: app}
daemonCmd.global = &globalCmd
Expand Down Expand Up @@ -185,7 +190,10 @@ func main() {
waitreadyCmd := cmdWaitready{global: &globalCmd}
app.AddCommand(waitreadyCmd.Command())

// cluster sub-command
// cluster sub-command (also admin cluster)
adminCmd := cmdAdmin{global: &globalCmd}
app.AddCommand(adminCmd.Command())

clusterCmd := cmdCluster{global: &globalCmd}
app.AddCommand(clusterCmd.Command())

Expand Down
21 changes: 21 additions & 0 deletions cmd/incusd/main_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,31 @@ import (
"github.com/lxc/incus/v6/shared/termios"
)

type cmdAdmin struct {
global *cmdGlobal
}

// Command returns a cobra command for inclusion.
func (c *cmdAdmin) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Hidden = true
cmd.Use = "admin"

// Cluster
clusterCmd := cmdCluster{global: c.global}
cmd.AddCommand(clusterCmd.Command())

// Workaround for subcommand usage errors. See: https://github.com/spf13/cobra/issues/706
cmd.Args = cobra.NoArgs
cmd.Run = func(cmd *cobra.Command, args []string) { _ = cmd.Usage() }
return cmd
}

type cmdCluster struct {
global *cmdGlobal
}

// Command returns a cobra command for inclusion.
func (c *cmdCluster) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "cluster"
Expand Down

0 comments on commit 955e6fa

Please sign in to comment.