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,
|
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…
x
Reference in New Issue
Block a user