Skip to content
Myr

Merge pull request #286 from dnephin/merge_flags_before_adding_help

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Merge persistent flags before checking for a help flag

authored by Eric Paris · committed by GitHub · parents b620a75, 7faa7fc · Browse files · 2 files+16 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−0 removed

  • other:+16 added−0 removed

2 files+16 added−0 removed

modified:command_test.go+15 added
134 unmodified lines
135 t.Errorf("expected: %v, got: %v", as, targs)136 }137}138139func TestInitHelpFlagMergesFlags(t *testing.T) {140 usage := "custom flag"141 baseCmd := Command{Use: "testcmd"}142 baseCmd.PersistentFlags().Bool("help", false, usage)143 cmd := Command{Use: "do"}144 baseCmd.AddCommand(&cmd)145146 cmd.initHelpFlag()147 actual := cmd.Flags().Lookup("help").Usage148 if actual != usage {149 t.Fatalf("Expected the help flag from the base command with usage '%s', " +150 "but got the default with usage '%s'", usage, actual)151 }152}153154func TestCommandsAreSorted(t *testing.T) {155 EnableCommandSorting = true156157 originalNames := []string{"middle", "zlast", "afirst"}
60 unmodified lines
modified:command.go+1 added
733 unmodified lines
734 return cmd, nil735}736737func (c *Command) initHelpFlag() {738 c.mergePersistentFlags()739 if c.Flags().Lookup("help") == nil {740 c.Flags().BoolP("help", "h", false, "help for "+c.Name())741 }742}
539 unmodified lines