Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func SetupRootCommand(rootCmd *cobra.Command) {

rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
rootCmd.PersistentFlags().Lookup("help").Hidden = true
Copy link
Member

Choose a reason for hiding this comment

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

hm, didn't the .golden file need to be updated? https://github.com/docker/cli/pull/642/files#r147009761

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expected it would, but it doesn't because of how the flags are applied.

This help flag is applied as a persistent flag to the root command, so when commands are added to the root, they inherit this version of the flag, and don't add the default.

In the test we are testing directly against the swarm update command, so the root command is not there to provide this flag. Cobra adds its own default help flag that is not hidden, so the test output still contains the --help flag.

}

// FlagErrorFunc prints an error message which matches the format of the
Expand Down Expand Up @@ -100,7 +101,7 @@ func managementSubCommands(cmd *cobra.Command) []*cobra.Command {

// UseLine returns the usage line for a command. This implementation is different
// from the default Command.UseLine in that it does not add a `[flags]` to the
// of the line.
// end of the line.
func UseLine(cmd *cobra.Command) string {
if cmd.HasParent() {
return cmd.Parent().CommandPath() + " " + cmd.Use
Expand Down