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.
()
| 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. |
| 1219 | func (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. |