MCPcopy
hub / github.com/spf13/cobra / InitDefaultHelpFlag

Method InitDefaultHelpFlag

command.go:1219–1232  ·  view source on GitHub ↗

InitDefaultHelpFlag adds default help flag to c. It is called automatically by executing the c or by calling help and usage. If c already has help flag, it will do nothing.

()

Source from the content-addressed store, hash-verified

1217// It is called automatically by executing the c or by calling help and usage.
1218// If c already has help flag, it will do nothing.
1219func (c *Command) InitDefaultHelpFlag() {
1220 c.mergePersistentFlags()
1221 if c.Flags().Lookup(helpFlagName) == nil {
1222 usage := "help for "
1223 name := c.DisplayName()
1224 if name == "" {
1225 usage += "this command"
1226 } else {
1227 usage += name
1228 }
1229 c.Flags().BoolP(helpFlagName, "h", false, usage)
1230 _ = c.Flags().SetAnnotation(helpFlagName, FlagSetByCobraAnnotation, []string{"true"})
1231 }
1232}
1233
1234// InitDefaultVersionFlag adds default version flag to c.
1235// It is called automatically by executing the c.

Callers 8

getCompletionsMethod · 0.95
executeMethod · 0.95
InitDefaultHelpCmdMethod · 0.80
genManFunction · 0.80
GenYamlCustomFunction · 0.80
GenReSTCustomFunction · 0.80
GenMarkdownCustomFunction · 0.80

Calls 3

mergePersistentFlagsMethod · 0.95
FlagsMethod · 0.95
DisplayNameMethod · 0.95

Tested by 1