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

```go
package main

import (
	"github.com/spf13/cobra"
	"github.com/spf13/pflag"
)

func main() {
	cmd := &cobra.Command{
		Use:   "min",
		Short: "minimal command",
		Run:   func(_ *cobra.Command, _ []string) {},
	}

	pflag.String("oncmdline", "oncmdline", "oncmdline")
	cmd.Execute()
}
```

Is a minimal cobra program.  When --help is displayed without this patch
you only get:

But with the patch --oncmdline is shows under flags.
This commit is contained in:
Eric Paris
2015-08-16 22:14:43 -07:00
parent c55cdf3385
commit e8bd799c1c
2 changed files with 15 additions and 1 deletions

View File

@ -963,3 +963,11 @@ func TestGlobalNormFuncPropagation(t *testing.T) {
t.Error("cmdPrint and cmdEchoSub should had the normalization function of rootCmd")
}
}
func TestFlagOnPflagCommandLine(t *testing.T) {
flagName := "flagOnCommandLine"
pflag.CommandLine.String(flagName, "", "about my flag")
r := fullSetupTest("--help")
checkResultContains(t, r, flagName)
}