mirror of https://github.com/docker/cli.git
Merge pull request #4389 from thaJeztah/remove_redundant_flag
cli: SetupRootCommand: remove redundant flags return
This commit is contained in:
commit
cb1def79e5
|
@ -131,7 +131,7 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta
|
|||
DisableDescriptions: true,
|
||||
},
|
||||
}
|
||||
opts, flags := cli.SetupPluginRootCommand(cmd)
|
||||
opts, _ := cli.SetupPluginRootCommand(cmd)
|
||||
|
||||
cmd.SetIn(dockerCli.In())
|
||||
cmd.SetOut(dockerCli.Out())
|
||||
|
@ -144,7 +144,7 @@ func newPluginCommand(dockerCli *command.DockerCli, plugin *cobra.Command, meta
|
|||
|
||||
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 {
|
||||
|
|
13
cli/cobra.go
13
cli/cobra.go
|
@ -22,10 +22,9 @@ import (
|
|||
|
||||
// setupCommonRootCommand contains the setup common to
|
||||
// SetupRootCommand and SetupPluginRootCommand.
|
||||
func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet, *cobra.Command) {
|
||||
flags := rootCmd.Flags()
|
||||
func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *cobra.Command) {
|
||||
opts := cliflags.NewClientOptions()
|
||||
opts.InstallFlags(flags)
|
||||
opts.InstallFlags(rootCmd.Flags())
|
||||
|
||||
cobra.AddTemplateFunc("add", func(a, b int) int { return a + b })
|
||||
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
|
||||
// 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")
|
||||
return setupCommonRootCommand(rootCmd)
|
||||
}
|
||||
|
||||
// SetupPluginRootCommand sets default usage, help and error handling for a plugin root command.
|
||||
func SetupPluginRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *pflag.FlagSet) {
|
||||
opts, flags, _ := setupCommonRootCommand(rootCmd)
|
||||
return opts, flags
|
||||
opts, _ := setupCommonRootCommand(rootCmd)
|
||||
return opts, rootCmd.Flags()
|
||||
}
|
||||
|
||||
// FlagErrorFunc prints an error message which matches the format of the
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
|
||||
var (
|
||||
opts *cliflags.ClientOptions
|
||||
flags *pflag.FlagSet
|
||||
helpCmd *cobra.Command
|
||||
)
|
||||
|
||||
|
@ -55,9 +54,9 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
|
|||
cmd.SetOut(dockerCli.Out())
|
||||
cmd.SetErr(dockerCli.Err())
|
||||
|
||||
opts, flags, helpCmd = cli.SetupRootCommand(cmd)
|
||||
opts, helpCmd = cli.SetupRootCommand(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)
|
||||
|
||||
setupHelpCommand(dockerCli, cmd, helpCmd)
|
||||
|
@ -70,7 +69,7 @@ func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
|
|||
setValidateArgs(dockerCli, cmd)
|
||||
|
||||
// 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) {
|
||||
|
|
|
@ -37,7 +37,7 @@ func gen(opts *options) error {
|
|||
Use: "docker [OPTIONS] COMMAND [ARG...]",
|
||||
Short: "The base command for the Docker CLI.",
|
||||
}
|
||||
clientOpts, _, _ := cli.SetupRootCommand(cmd)
|
||||
clientOpts, _ := cli.SetupRootCommand(cmd)
|
||||
if err := dockerCLI.Initialize(clientOpts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue