-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update Cobra and pflag, and use built-in --version feature #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,13 +32,6 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { | |
| SilenceErrors: true, | ||
| TraverseChildren: true, | ||
| Args: noArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if opts.Version { | ||
| showVersion() | ||
| return nil | ||
| } | ||
| return command.ShowHelp(dockerCli.Err())(cmd, args) | ||
| }, | ||
| PersistentPreRunE: func(cmd *cobra.Command, args []string) error { | ||
| // flags must be the top-level command flags, not cmd.Flags() | ||
| opts.Common.SetDefaultOptions(flags) | ||
|
|
@@ -48,11 +41,13 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { | |
| } | ||
| return isSupported(cmd, dockerCli) | ||
| }, | ||
| Version: fmt.Sprintf("%s, build %s", cli.Version, cli.GitCommit), | ||
| DisableFlagsInUseLine: true, | ||
| } | ||
| cli.SetupRootCommand(cmd) | ||
|
|
||
| flags = cmd.Flags() | ||
| flags.BoolVarP(&opts.Version, "version", "v", false, "Print version information and quit") | ||
| flags.BoolP("version", "v", false, "Print version information and quit") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately still needed; our flag-description has a short-hand ( Whereas the built-in flag for Cobra doesn't have a shorthand, and looks like this; |
||
| flags.StringVar(&opts.ConfigDir, "config", cliconfig.Dir(), "Location of client config files") | ||
| opts.Common.InstallFlags(flags) | ||
|
|
||
|
|
@@ -63,11 +58,19 @@ func newDockerCommand(dockerCli *command.DockerCli) *cobra.Command { | |
| cmd.SetOutput(dockerCli.Out()) | ||
| commands.AddCommands(cmd, dockerCli) | ||
|
|
||
| disableFlagsInUseLine(cmd) | ||
| setValidateArgs(dockerCli, cmd, flags, opts) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func disableFlagsInUseLine(cmd *cobra.Command) { | ||
| visitAll(cmd, func(ccmd *cobra.Command) { | ||
| // do not add a `[flags]` to the end of the usage line. | ||
| ccmd.DisableFlagsInUseLine = true | ||
| }) | ||
| } | ||
|
|
||
| func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) { | ||
| // When invoking `docker stack --nonsense`, we need to make sure FlagErrorFunc return appropriate | ||
| // output if the feature is not supported. | ||
|
|
@@ -186,10 +189,6 @@ func contentTrustEnabled() bool { | |
| return false | ||
| } | ||
|
|
||
| func showVersion() { | ||
| fmt.Printf("Docker version %s, build %s\n", cli.Version, cli.GitCommit) | ||
| } | ||
|
|
||
| func dockerPreRun(opts *cliflags.ClientOptions) { | ||
| cliflags.SetLogLevel(opts.Common.LogLevel) | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure if we needed this; without this,
dockerwill be printed lowercase (i.e., name of the binary). If we think that's ok, I can remove this