Skip to content
Myr

Merge pull request #127 from eparis/show-commandline-on-parent

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

Display pflag.CommandLine flags as if they were declared on the parent

authored by Eric Paris · committed by Eric Paris · parents c55cdf3, e8bd799 · Browse files · 2 files+15 added−1 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+15 added−1 removed

  • other:+15 added−1 removed

2 files+15 added−1 removed

modified:cobra_test.go+8 added
961 unmodified lines
962 reflect.ValueOf(cmdEchoSub.GlobalNormalizationFunc()).Pointer() != reflect.ValueOf(rootCmd.GlobalNormalizationFunc()).Pointer() {963 t.Error("cmdPrint and cmdEchoSub should had the normalization function of rootCmd")964 }965}966967func TestFlagOnPflagCommandLine(t *testing.T) {968 flagName := "flagOnCommandLine"969 pflag.CommandLine.String(flagName, "", "about my flag")970 r := fullSetupTest("--help")971972 checkResultContains(t, r, flagName)973}
modified:command.go+7 added-1 removed
156 unmodified lines
157// The user should not have a cyclic dependency on commands.158func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string) flag.NormalizedName) {159 c.Flags().SetNormalizeFunc(n)160 c.PersistentFlags().SetNormalizeFunc(n)161 c.LocalFlags().SetNormalizeFunc(n)161 c.globNormFunc = n162163 for _, command := range c.commands {164 command.SetGlobalNormalizationFunc(n)
706 unmodified lines
871 local := flag.NewFlagSet(c.Name(), flag.ContinueOnError)872 c.lflags.VisitAll(func(f *flag.Flag) {873 local.AddFlag(f)874 })875 if !c.HasParent() {876 flag.CommandLine.VisitAll(func(f *flag.Flag) {877 if local.Lookup(f.Name) == nil {878 local.AddFlag(f)879 }880 })881 }882 return local883}884885// All Flags which were inherited from parents commands
146 unmodified lines