chore(cmd): add subcommands in one call (#819)

pull/827/head
Maxim Eryomenko 3 years ago committed by GitHub
parent 7113694ab5
commit 407ced6405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      cmd/cluster/cluster.go
  2. 3
      cmd/config/config.go
  3. 3
      cmd/kubeconfig/kubeconfig.go
  4. 12
      cmd/node/node.go
  5. 10
      cmd/registry/registry.go
  6. 64
      cmd/root.go

@ -44,12 +44,12 @@ func NewCmdCluster() *cobra.Command {
} }
// add subcommands // add subcommands
cmd.AddCommand(NewCmdClusterCreate()) cmd.AddCommand(NewCmdClusterCreate(),
cmd.AddCommand(NewCmdClusterStart()) NewCmdClusterStart(),
cmd.AddCommand(NewCmdClusterStop()) NewCmdClusterStop(),
cmd.AddCommand(NewCmdClusterDelete()) NewCmdClusterDelete(),
cmd.AddCommand(NewCmdClusterList()) NewCmdClusterList(),
cmd.AddCommand(NewCmdClusterEdit()) NewCmdClusterEdit())
// add flags // add flags

@ -41,8 +41,7 @@ func NewCmdConfig() *cobra.Command {
}, },
} }
cmd.AddCommand(NewCmdConfigInit()) cmd.AddCommand(NewCmdConfigInit(), NewCmdConfigMigrate())
cmd.AddCommand(NewCmdConfigMigrate())
return cmd return cmd
} }

@ -43,8 +43,7 @@ func NewCmdKubeconfig() *cobra.Command {
} }
// add subcommands // add subcommands
cmd.AddCommand(NewCmdKubeconfigGet()) cmd.AddCommand(NewCmdKubeconfigGet(), NewCmdKubeconfigMerge())
cmd.AddCommand(NewCmdKubeconfigMerge())
// add flags // add flags

@ -43,12 +43,12 @@ func NewCmdNode() *cobra.Command {
} }
// add subcommands // add subcommands
cmd.AddCommand(NewCmdNodeCreate()) cmd.AddCommand(NewCmdNodeCreate(),
cmd.AddCommand(NewCmdNodeStart()) NewCmdNodeStart(),
cmd.AddCommand(NewCmdNodeStop()) NewCmdNodeStop(),
cmd.AddCommand(NewCmdNodeDelete()) NewCmdNodeDelete(),
cmd.AddCommand(NewCmdNodeList()) NewCmdNodeList(),
cmd.AddCommand(NewCmdNodeEdit()) NewCmdNodeEdit())
// add flags // add flags

@ -44,11 +44,11 @@ func NewCmdRegistry() *cobra.Command {
} }
// add subcommands // add subcommands
cmd.AddCommand(NewCmdRegistryCreate()) cmd.AddCommand(NewCmdRegistryCreate(),
cmd.AddCommand(NewCmdRegistryStart()) NewCmdRegistryStart(),
cmd.AddCommand(NewCmdRegistryStop()) NewCmdRegistryStop(),
cmd.AddCommand(NewCmdRegistryDelete()) NewCmdRegistryDelete(),
cmd.AddCommand(NewCmdRegistryList()) NewCmdRegistryList())
// add flags // add flags

@ -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") rootCmd.Flags().BoolVar(&flags.version, "version", false, "Show k3d and default k3s version")
// add subcommands // add subcommands
rootCmd.AddCommand(NewCmdCompletion(rootCmd)) rootCmd.AddCommand(NewCmdCompletion(rootCmd),
rootCmd.AddCommand(cluster.NewCmdCluster()) cluster.NewCmdCluster(),
rootCmd.AddCommand(kubeconfig.NewCmdKubeconfig()) kubeconfig.NewCmdKubeconfig(),
rootCmd.AddCommand(node.NewCmdNode()) node.NewCmdNode(),
rootCmd.AddCommand(image.NewCmdImage()) image.NewCmdImage(),
rootCmd.AddCommand(cfg.NewCmdConfig()) cfg.NewCmdConfig(),
rootCmd.AddCommand(registry.NewCmdRegistry()) registry.NewCmdRegistry(),
rootCmd.AddCommand(debug.NewCmdDebug()) debug.NewCmdDebug(),
&cobra.Command{
rootCmd.AddCommand(&cobra.Command{ Use: "version",
Use: "version", Short: "Show k3d and default k3s version",
Short: "Show k3d and default k3s version", Long: "Show k3d and default k3s version",
Long: "Show k3d and default k3s version", Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, args []string) { printVersion()
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)
}
}, },
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 // Init
cobra.OnInitialize(initLogging, initRuntime) cobra.OnInitialize(initLogging, initRuntime)

Loading…
Cancel
Save