From 38645ca44a6a7f44978de42a42238bd2be63590e Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 18 Dec 2018 10:02:47 +0000 Subject: [PATCH] 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 --- cli/cobra.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cli/cobra.go b/cli/cobra.go index b0c50a2aa9..1e83a0ef4e 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -9,9 +9,7 @@ import ( "github.com/spf13/cobra" ) -// SetupRootCommand sets default usage, help, and error handling for the -// root command. -func SetupRootCommand(rootCmd *cobra.Command) { +func setupCommonRootCommand(rootCmd *cobra.Command) { cobra.AddTemplateFunc("hasSubCommands", hasSubCommands) cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands) cobra.AddTemplateFunc("operationSubCommands", operationSubCommands) @@ -22,6 +20,13 @@ func SetupRootCommand(rootCmd *cobra.Command) { rootCmd.SetHelpTemplate(helpTemplate) rootCmd.SetFlagErrorFunc(FlagErrorFunc) 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.PersistentFlags().BoolP("help", "h", false, "Print usage")