Skip to content

Commit

Permalink
make string "help" a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
aarzilli committed Dec 6, 2024
1 parent 5e44e3e commit 45cac89
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
const (
FlagSetByCobraAnnotation = "cobra_annotation_flag_set_by_cobra"
CommandDisplayNameAnnotation = "cobra_annotation_command_display_name"

helpFlagName = "help"
)

// FParseErrWhitelist configures Flag parse errors to be ignored
Expand Down Expand Up @@ -1168,16 +1170,16 @@ func (c *Command) checkCommandGroups() {
// If c already has help flag, it will do nothing.
func (c *Command) InitDefaultHelpFlag() {
c.mergePersistentFlags()
if c.Flags().Lookup("help") == nil {
if c.Flags().Lookup(helpFlagName) == nil {
usage := "help for "
name := c.DisplayName()
if name == "" {
usage += "this command"
} else {
usage += name
}
c.Flags().BoolP("help", "h", false, usage)
_ = c.Flags().SetAnnotation("help", FlagSetByCobraAnnotation, []string{"true"})
c.Flags().BoolP(helpFlagName, "h", false, usage)
_ = c.Flags().SetAnnotation(helpFlagName, FlagSetByCobraAnnotation, []string{"true"})
}
}

Expand Down

0 comments on commit 45cac89

Please sign in to comment.