Skip to content
Myr

Merge persistent flags before checking for a help flag.

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

authored by Daniel Nephin · committed by Daniel Nephin · parent bc81c21 · 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.

Trailers

  • Signed-off-by: Daniel Nephin <dnephin@gmail.com>

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
132 unmodified lines
133 t.Errorf("expected: %v, got: %v", as, targs)134 }135}136137func TestInitHelpFlagMergesFlags(t *testing.T) {138 usage := "custom flag"139 baseCmd := Command{Use: "testcmd"}140 baseCmd.PersistentFlags().Bool("help", false, usage)141 cmd := Command{Use: "do"}142 baseCmd.AddCommand(&cmd)143144 cmd.initHelpFlag()145 actual := cmd.Flags().Lookup("help").Usage146 if actual != usage {147 t.Fatalf("Expected the help flag from the base command with usage '%s', " +148 "but got the default with usage '%s'", usage, actual)149 }150}151152func TestCommandsAreSorted(t *testing.T) {153 EnableCommandSorting = true154155 originalNames := []string{"middle", "zlast", "afirst"}
36 unmodified lines
modified:command.go+1 added
682 unmodified lines
683 return cmd, nil684}685686func (c *Command) initHelpFlag() {687 c.mergePersistentFlags()688 if c.Flags().Lookup("help") == nil {689 c.Flags().BoolP("help", "h", false, "help for "+c.Name())690 }691}
566 unmodified lines