mirror of https://github.com/docker/cli.git
				
				
				
			cli: SetupRootCommand: remove redundant flags return
The flag-set that was returned is a pointer to the command's Flags(), which is in itself passed by reference (as it is modified / set up). This patch removes the flags return, to prevent assuming it's different than the command's flags. While SetupRootCommand is exported, a search showed that it's only used internally, so changing the signature should not be a problem. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
		
							parent
							
								
									d2b376da92
								
							
						
					
					
						commit
						88f44ec159
					
				|  | @ -131,7 +131,7 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta | ||||||
| 			DisableDescriptions: true, | 			DisableDescriptions: true, | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	opts, flags := cli.SetupPluginRootCommand(cmd) | 	opts, _ := cli.SetupPluginRootCommand(cmd) | ||||||
| 
 | 
 | ||||||
| 	cmd.SetIn(dockerCli.In()) | 	cmd.SetIn(dockerCli.In()) | ||||||
| 	cmd.SetOut(dockerCli.Out()) | 	cmd.SetOut(dockerCli.Out()) | ||||||
|  | @ -144,7 +144,7 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta | ||||||
| 
 | 
 | ||||||
| 	cli.DisableFlagsInUseLine(cmd) | 	cli.DisableFlagsInUseLine(cmd) | ||||||
| 
 | 
 | ||||||
| 	return cli.NewTopLevelCommand(cmd, dockerCli, opts, flags) | 	return cli.NewTopLevelCommand(cmd, dockerCli, opts, cmd.Flags()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func newMetadataSubcommand(plugin *cobra.Command, meta manager.Metadata) *cobra.Command { | func newMetadataSubcommand(plugin *cobra.Command, meta manager.Metadata) *cobra.Command { | ||||||
|  |  | ||||||
							
								
								
									
										13
									
								
								cli/cobra.go
								
								
								
								
							
							
						
						
									
										13
									
								
								cli/cobra.go
								
								
								
								
							|  | @ -22,10 +22,9 @@ import ( | ||||||
| 
 | 
 | ||||||
| // setupCommonRootCommand contains the setup common to
 | // setupCommonRootCommand contains the setup common to
 | ||||||
| // SetupRootCommand and SetupPluginRootCommand.
 | // SetupRootCommand and SetupPluginRootCommand.
 | ||||||
| func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet, *cobra.Command) { | func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *cobra.Command) { | ||||||
| 	flags := rootCmd.Flags() |  | ||||||
| 	opts := cliflags.NewClientOptions() | 	opts := cliflags.NewClientOptions() | ||||||
| 	opts.InstallFlags(flags) | 	opts.InstallFlags(rootCmd.Flags()) | ||||||
| 
 | 
 | ||||||
| 	cobra.AddTemplateFunc("add", func(a, b int) int { return a + b }) | 	cobra.AddTemplateFunc("add", func(a, b int) int { return a + b }) | ||||||
| 	cobra.AddTemplateFunc("hasAliases", hasAliases) | 	cobra.AddTemplateFunc("hasAliases", hasAliases) | ||||||
|  | @ -70,20 +69,20 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return opts, flags, helpCommand | 	return opts, helpCommand | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // SetupRootCommand sets default usage, help, and error handling for the
 | // SetupRootCommand sets default usage, help, and error handling for the
 | ||||||
| // root command.
 | // root command.
 | ||||||
| func SetupRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet, *cobra.Command) { | func SetupRootCommand(rootCmd *cobra.Command) (opts *cliflags.ClientOptions, helpCmd *cobra.Command) { | ||||||
| 	rootCmd.SetVersionTemplate("Docker version {{.Version}}\n") | 	rootCmd.SetVersionTemplate("Docker version {{.Version}}\n") | ||||||
| 	return setupCommonRootCommand(rootCmd) | 	return setupCommonRootCommand(rootCmd) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // SetupPluginRootCommand sets default usage, help and error handling for a plugin root command.
 | // SetupPluginRootCommand sets default usage, help and error handling for a plugin root command.
 | ||||||
| func SetupPluginRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet) { | func SetupPluginRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet) { | ||||||
| 	opts, flags, _ := setupCommonRootCommand(rootCmd) | 	opts, _ := setupCommonRootCommand(rootCmd) | ||||||
| 	return opts, flags | 	return opts, rootCmd.Flags() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // FlagErrorFunc prints an error message which matches the format of the
 | // FlagErrorFunc prints an error message which matches the format of the
 | ||||||
|  |  | ||||||
|  | @ -24,7 +24,6 @@ import ( | ||||||
| func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand { | func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand { | ||||||
| 	var ( | 	var ( | ||||||
| 		opts    *cliflags.ClientOptions | 		opts    *cliflags.ClientOptions | ||||||
| 		flags   *pflag.FlagSet |  | ||||||
| 		helpCmd *cobra.Command | 		helpCmd *cobra.Command | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
|  | @ -55,9 +54,9 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand { | ||||||
| 	cmd.SetOut(dockerCli.Out()) | 	cmd.SetOut(dockerCli.Out()) | ||||||
| 	cmd.SetErr(dockerCli.Err()) | 	cmd.SetErr(dockerCli.Err()) | ||||||
| 
 | 
 | ||||||
| 	opts, flags, helpCmd = cli.SetupRootCommand(cmd) | 	opts, helpCmd = cli.SetupRootCommand(cmd) | ||||||
| 	registerCompletionFuncForGlobalFlags(dockerCli, cmd) | 	registerCompletionFuncForGlobalFlags(dockerCli, cmd) | ||||||
| 	flags.BoolP("version", "v", false, "Print version information and quit") | 	cmd.Flags().BoolP("version", "v", false, "Print version information and quit") | ||||||
| 	setFlagErrorFunc(dockerCli, cmd) | 	setFlagErrorFunc(dockerCli, cmd) | ||||||
| 
 | 
 | ||||||
| 	setupHelpCommand(dockerCli, cmd, helpCmd) | 	setupHelpCommand(dockerCli, cmd, helpCmd) | ||||||
|  | @ -70,7 +69,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand { | ||||||
| 	setValidateArgs(dockerCli, cmd) | 	setValidateArgs(dockerCli, cmd) | ||||||
| 
 | 
 | ||||||
| 	// flags must be the top-level command flags, not cmd.Flags()
 | 	// flags must be the top-level command flags, not cmd.Flags()
 | ||||||
| 	return cli.NewTopLevelCommand(cmd, dockerCli, opts, flags) | 	return cli.NewTopLevelCommand(cmd, dockerCli, opts, cmd.Flags()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func setFlagErrorFunc(dockerCli command.Cli, cmd *cobra.Command) { | func setFlagErrorFunc(dockerCli command.Cli, cmd *cobra.Command) { | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ func gen(opts *options) error { | ||||||
| 		Use:   "docker [OPTIONS] COMMAND [ARG...]", | 		Use:   "docker [OPTIONS] COMMAND [ARG...]", | ||||||
| 		Short: "The base command for the Docker CLI.", | 		Short: "The base command for the Docker CLI.", | ||||||
| 	} | 	} | ||||||
| 	clientOpts, _, _ := cli.SetupRootCommand(cmd) | 	clientOpts, _ := cli.SetupRootCommand(cmd) | ||||||
| 	if err := dockerCLI.Initialize(clientOpts); err != nil { | 	if err := dockerCLI.Initialize(clientOpts); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue