mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Merge pull request #133 from eparis/late-init-help-flag
Initialize the --help flag as late as possible
This commit is contained in:
commit
4c4f2d9417
1 changed files with 3 additions and 1 deletions
|
@ -561,6 +561,9 @@ func (c *Command) Execute() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) initHelp() {
|
func (c *Command) initHelp() {
|
||||||
|
if c.Flags().Lookup("help") == nil {
|
||||||
|
c.Flags().BoolVarP(&c.helpFlagVal, "help", "h", false, "help for "+c.Name())
|
||||||
|
}
|
||||||
if c.helpCommand == nil {
|
if c.helpCommand == nil {
|
||||||
if !c.HasSubCommands() {
|
if !c.HasSubCommands() {
|
||||||
return
|
return
|
||||||
|
@ -859,7 +862,6 @@ func (c *Command) Flags() *flag.FlagSet {
|
||||||
c.flagErrorBuf = new(bytes.Buffer)
|
c.flagErrorBuf = new(bytes.Buffer)
|
||||||
}
|
}
|
||||||
c.flags.SetOutput(c.flagErrorBuf)
|
c.flags.SetOutput(c.flagErrorBuf)
|
||||||
c.PersistentFlags().BoolVarP(&c.helpFlagVal, "help", "h", false, "help for "+c.Name())
|
|
||||||
}
|
}
|
||||||
return c.flags
|
return c.flags
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue