Skip to content
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

Update Cobra and pflag, and use built-in --version feature #1069

Merged
merged 3 commits into from
May 21, 2018

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented May 18, 2018

This updates cobra and pflag to tagged releases, and uses the new built-in --version feature.

Also hides [flags] in the usage output of commands, using the new .DisableFlagsInUseLine option, instead of the temporary workaround added in 8e600e1 (#642)

Before this change:

docker run
"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...] [flags]

Run a command in a new container

After this change:

docker run
"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

Bump spf13/cobra to v0.0.3

Use a tagged release of Cobra

spf13/cobra@34ceca5...v0.0.3

Relevant changes:

Also various improvements were added for generating Bash
completion scripts (currently not used by us)

Bump spf13/pflag to v1.0.1

Use a tagged release of this package

spf13/pflag@97afa5e...v1.0.1

Relevant changes:

@@ -23,6 +23,7 @@ func SetupRootCommand(rootCmd *cobra.Command) {
rootCmd.SetHelpTemplate(helpTemplate)
rootCmd.SetFlagErrorFunc(FlagErrorFunc)
rootCmd.SetHelpCommand(helpCommand)
rootCmd.SetVersionTemplate("Docker version {{.Version}}\n")
Copy link
Member Author

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, docker will be printed lowercase (i.e., name of the binary). If we think that's ok, I can remove this

}
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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately still needed; our flag-description has a short-hand (-v), and looks like;

 -v, --version            Print version information and quit

Whereas the built-in flag for Cobra doesn't have a shorthand, and looks like this;

      --version            version for docker

Use a tagged release of Cobra

Relevant changes:

- spf13/cobra#567 Add `CalledAs` method to cobra.Command
- spf13/cobra#580 Update error message for missing required flags
- spf13/cobra#584 Add support for --version flag
- spf13/cobra#614 If user has a project in symlink, just use its destination folder and work there
- spf13/cobra#649 terminates the flags when -- is found in commandline
- spf13/cobra#662 Add support for ignoring parse errors
- spf13/cobra#686 doc: hide hidden parent flags

Also various improvements were added for generating Bash
completion scripts (currently not used by us)

Bump spf13/pflag to v1.0.1

Relevant changes:

- spf13/pflag#122 DurationSlice: implementation and tests
- spf13/pflag#115 Implement BytesHex type of argument
- spf13/pflag#150 Add uintSlice and boolSlice to name prettifier
- spf13/pflag#155 Add multiline wrapping support
- spf13/pflag#158 doc: clarify difference between string slice vs. array
- spf13/pflag#160 add ability to ignore unknown flags
- spf13/pflag#163 Allow Users To Show Deprecated Flags

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This patch hides the [flags] in the usage output of commands, using the
new `.DisableFlagsInUseLine` option, instead of the temporary workaround
added in 8e600e1

Before this change:

    docker run
    "docker run" requires at least 1 argument.
    See 'docker run --help'.

    Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...] [flags]

    Run a command in a new container

After this change:

    docker run
    "docker run" requires at least 1 argument.
    See 'docker run --help'.

    Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

    Run a command in a new container

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Copy link
Contributor

@vieux vieux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants