Add merging of CommandLine flags to Root command
This commit is contained in:
parent
37a4355faa
commit
458d79748e
@ -1147,6 +1147,14 @@ func TestGlobalNormFuncPropagation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFlagOnPflagCommandLine(t *testing.T) {
|
||||||
|
flagName := "flagOnCommandLine"
|
||||||
|
pflag.CommandLine.String(flagName, "", "about my flag")
|
||||||
|
r := fullSetupTest("--help")
|
||||||
|
|
||||||
|
checkResultContains(t, r, flagName)
|
||||||
|
}
|
||||||
|
|
||||||
func TestAddTemplateFunctions(t *testing.T) {
|
func TestAddTemplateFunctions(t *testing.T) {
|
||||||
AddTemplateFunc("t", func() bool { return true })
|
AddTemplateFunc("t", func() bool { return true })
|
||||||
AddTemplateFuncs(template.FuncMap{
|
AddTemplateFuncs(template.FuncMap{
|
||||||
|
@ -1258,6 +1258,8 @@ func (c *Command) updateParentsPflags() (added []*flag.Flag) {
|
|||||||
c.parentsPflags.SortFlags = false
|
c.parentsPflags.SortFlags = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Root().PersistentFlags().AddFlagSet(flag.CommandLine)
|
||||||
|
|
||||||
c.VisitParents(func(x *Command) {
|
c.VisitParents(func(x *Command) {
|
||||||
if x.HasPersistentFlags() {
|
if x.HasPersistentFlags() {
|
||||||
x.PersistentFlags().VisitAll(func(f *flag.Flag) {
|
x.PersistentFlags().VisitAll(func(f *flag.Flag) {
|
||||||
|
Loading…
Reference in New Issue
Block a user