File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,6 +159,8 @@ type Command struct {
159159 shellCompletion bool
160160 // whether global help flag was added
161161 globaHelpFlagAdded bool
162+ // whether global version flag was added
163+ globaVersionFlagAdded bool
162164}
163165
164166// FullName returns the full name of the command.
Original file line number Diff line number Diff line change @@ -80,7 +80,24 @@ func (cmd *Command) setupDefaults(osArgs []string) {
8080
8181 if ! cmd .HideVersion && isRoot {
8282 tracef ("appending version flag (cmd=%[1]q)" , cmd .Name )
83- cmd .appendFlag (VersionFlag )
83+ if ! cmd .globaVersionFlagAdded {
84+ var localVersionFlag Flag
85+ if globalVersionFlag , ok := VersionFlag .(* BoolFlag ); ok {
86+ // clone VersionFlag
87+ localVersionFlag = & BoolFlag {
88+ Name : globalVersionFlag .Name ,
89+ Aliases : globalVersionFlag .Aliases ,
90+ Usage : globalVersionFlag .Usage ,
91+ HideDefault : globalVersionFlag .HideDefault ,
92+ Local : globalVersionFlag .Local ,
93+ }
94+ } else {
95+ localVersionFlag = VersionFlag
96+ }
97+
98+ cmd .appendFlag (localVersionFlag )
99+ cmd .globaVersionFlagAdded = true
100+ }
84101 }
85102
86103 if cmd .PrefixMatchCommands && cmd .SuggestCommandFunc == nil {
You can’t perform that action at this time.
0 commit comments