mirror of https://github.com/docker/cli.git
Refactor common bits of `SetupRootCommand`
I'm shortly going to add a second user to setup plugins, which will want to reuse the common bits. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
ccef1598b1
commit
38645ca44a
11
cli/cobra.go
11
cli/cobra.go
|
@ -9,9 +9,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupRootCommand sets default usage, help, and error handling for the
|
func setupCommonRootCommand(rootCmd *cobra.Command) {
|
||||||
// root command.
|
|
||||||
func SetupRootCommand(rootCmd *cobra.Command) {
|
|
||||||
cobra.AddTemplateFunc("hasSubCommands", hasSubCommands)
|
cobra.AddTemplateFunc("hasSubCommands", hasSubCommands)
|
||||||
cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands)
|
cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands)
|
||||||
cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
|
cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
|
||||||
|
@ -22,6 +20,13 @@ func SetupRootCommand(rootCmd *cobra.Command) {
|
||||||
rootCmd.SetHelpTemplate(helpTemplate)
|
rootCmd.SetHelpTemplate(helpTemplate)
|
||||||
rootCmd.SetFlagErrorFunc(FlagErrorFunc)
|
rootCmd.SetFlagErrorFunc(FlagErrorFunc)
|
||||||
rootCmd.SetHelpCommand(helpCommand)
|
rootCmd.SetHelpCommand(helpCommand)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupRootCommand sets default usage, help, and error handling for the
|
||||||
|
// root command.
|
||||||
|
func SetupRootCommand(rootCmd *cobra.Command) {
|
||||||
|
setupCommonRootCommand(rootCmd)
|
||||||
|
|
||||||
rootCmd.SetVersionTemplate("Docker version {{.Version}}\n")
|
rootCmd.SetVersionTemplate("Docker version {{.Version}}\n")
|
||||||
|
|
||||||
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
|
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
|
||||||
|
|
Loading…
Reference in New Issue