From 407ced6405b76138c79b9225717328c79efaed8a Mon Sep 17 00:00:00 2001 From: Maxim Eryomenko Date: Wed, 27 Oct 2021 10:43:10 +0300 Subject: [PATCH] chore(cmd): add subcommands in one call (#819) --- cmd/cluster/cluster.go | 12 +++---- cmd/config/config.go | 3 +- cmd/kubeconfig/kubeconfig.go | 3 +- cmd/node/node.go | 12 +++---- cmd/registry/registry.go | 10 +++--- cmd/root.go | 64 +++++++++++++++++------------------- 6 files changed, 50 insertions(+), 54 deletions(-) diff --git a/cmd/cluster/cluster.go b/cmd/cluster/cluster.go index 8ddb63b1..c3cfae35 100644 --- a/cmd/cluster/cluster.go +++ b/cmd/cluster/cluster.go @@ -44,12 +44,12 @@ func NewCmdCluster() *cobra.Command { } // add subcommands - cmd.AddCommand(NewCmdClusterCreate()) - cmd.AddCommand(NewCmdClusterStart()) - cmd.AddCommand(NewCmdClusterStop()) - cmd.AddCommand(NewCmdClusterDelete()) - cmd.AddCommand(NewCmdClusterList()) - cmd.AddCommand(NewCmdClusterEdit()) + cmd.AddCommand(NewCmdClusterCreate(), + NewCmdClusterStart(), + NewCmdClusterStop(), + NewCmdClusterDelete(), + NewCmdClusterList(), + NewCmdClusterEdit()) // add flags diff --git a/cmd/config/config.go b/cmd/config/config.go index e67df1e2..87aa173b 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -41,8 +41,7 @@ func NewCmdConfig() *cobra.Command { }, } - cmd.AddCommand(NewCmdConfigInit()) - cmd.AddCommand(NewCmdConfigMigrate()) + cmd.AddCommand(NewCmdConfigInit(), NewCmdConfigMigrate()) return cmd } diff --git a/cmd/kubeconfig/kubeconfig.go b/cmd/kubeconfig/kubeconfig.go index ed7c77c7..b93162c9 100644 --- a/cmd/kubeconfig/kubeconfig.go +++ b/cmd/kubeconfig/kubeconfig.go @@ -43,8 +43,7 @@ func NewCmdKubeconfig() *cobra.Command { } // add subcommands - cmd.AddCommand(NewCmdKubeconfigGet()) - cmd.AddCommand(NewCmdKubeconfigMerge()) + cmd.AddCommand(NewCmdKubeconfigGet(), NewCmdKubeconfigMerge()) // add flags diff --git a/cmd/node/node.go b/cmd/node/node.go index 7f879454..f56120f7 100644 --- a/cmd/node/node.go +++ b/cmd/node/node.go @@ -43,12 +43,12 @@ func NewCmdNode() *cobra.Command { } // add subcommands - cmd.AddCommand(NewCmdNodeCreate()) - cmd.AddCommand(NewCmdNodeStart()) - cmd.AddCommand(NewCmdNodeStop()) - cmd.AddCommand(NewCmdNodeDelete()) - cmd.AddCommand(NewCmdNodeList()) - cmd.AddCommand(NewCmdNodeEdit()) + cmd.AddCommand(NewCmdNodeCreate(), + NewCmdNodeStart(), + NewCmdNodeStop(), + NewCmdNodeDelete(), + NewCmdNodeList(), + NewCmdNodeEdit()) // add flags diff --git a/cmd/registry/registry.go b/cmd/registry/registry.go index 504392b9..5d597874 100644 --- a/cmd/registry/registry.go +++ b/cmd/registry/registry.go @@ -44,11 +44,11 @@ func NewCmdRegistry() *cobra.Command { } // add subcommands - cmd.AddCommand(NewCmdRegistryCreate()) - cmd.AddCommand(NewCmdRegistryStart()) - cmd.AddCommand(NewCmdRegistryStop()) - cmd.AddCommand(NewCmdRegistryDelete()) - cmd.AddCommand(NewCmdRegistryList()) + cmd.AddCommand(NewCmdRegistryCreate(), + NewCmdRegistryStart(), + NewCmdRegistryStop(), + NewCmdRegistryDelete(), + NewCmdRegistryList()) // add flags diff --git a/cmd/root.go b/cmd/root.go index 3ecab49f..56e407f9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -86,40 +86,38 @@ All Nodes of a k3d cluster are part of the same docker network.`, rootCmd.Flags().BoolVar(&flags.version, "version", false, "Show k3d and default k3s version") // add subcommands - rootCmd.AddCommand(NewCmdCompletion(rootCmd)) - rootCmd.AddCommand(cluster.NewCmdCluster()) - rootCmd.AddCommand(kubeconfig.NewCmdKubeconfig()) - rootCmd.AddCommand(node.NewCmdNode()) - rootCmd.AddCommand(image.NewCmdImage()) - rootCmd.AddCommand(cfg.NewCmdConfig()) - rootCmd.AddCommand(registry.NewCmdRegistry()) - rootCmd.AddCommand(debug.NewCmdDebug()) - - rootCmd.AddCommand(&cobra.Command{ - Use: "version", - Short: "Show k3d and default k3s version", - Long: "Show k3d and default k3s version", - Run: func(cmd *cobra.Command, args []string) { - printVersion() - }, - }) - - rootCmd.AddCommand(&cobra.Command{ - Use: "runtime-info", - Short: "Show runtime information", - Long: "Show some information about the runtime environment (e.g. docker info)", - Run: func(cmd *cobra.Command, args []string) { - info, err := runtimes.SelectedRuntime.Info() - if err != nil { - l.Log().Fatalln(err) - } - err = yaml.NewEncoder(os.Stdout).Encode(info) - if err != nil { - l.Log().Fatalln(err) - } + rootCmd.AddCommand(NewCmdCompletion(rootCmd), + cluster.NewCmdCluster(), + kubeconfig.NewCmdKubeconfig(), + node.NewCmdNode(), + image.NewCmdImage(), + cfg.NewCmdConfig(), + registry.NewCmdRegistry(), + debug.NewCmdDebug(), + &cobra.Command{ + Use: "version", + Short: "Show k3d and default k3s version", + Long: "Show k3d and default k3s version", + Run: func(cmd *cobra.Command, args []string) { + printVersion() + }, }, - Hidden: true, - }) + &cobra.Command{ + Use: "runtime-info", + Short: "Show runtime information", + Long: "Show some information about the runtime environment (e.g. docker info)", + Run: func(cmd *cobra.Command, args []string) { + info, err := runtimes.SelectedRuntime.Info() + if err != nil { + l.Log().Fatalln(err) + } + err = yaml.NewEncoder(os.Stdout).Encode(info) + if err != nil { + l.Log().Fatalln(err) + } + }, + Hidden: true, + }) // Init cobra.OnInitialize(initLogging, initRuntime)