InitDefaultVersionFlag adds default version flag to c. It is called automatically by executing the c. If c already has a version flag, it will do nothing. If c.Version is empty, it will do nothing.
()
| 1236 | // If c already has a version flag, it will do nothing. |
| 1237 | // If c.Version is empty, it will do nothing. |
| 1238 | func (c *Command) InitDefaultVersionFlag() { |
| 1239 | if c.Version == "" { |
| 1240 | return |
| 1241 | } |
| 1242 | |
| 1243 | c.mergePersistentFlags() |
| 1244 | if c.Flags().Lookup("version") == nil { |
| 1245 | usage := "version for " |
| 1246 | if c.Name() == "" { |
| 1247 | usage += "this command" |
| 1248 | } else { |
| 1249 | usage += c.DisplayName() |
| 1250 | } |
| 1251 | if c.Flags().ShorthandLookup("v") == nil { |
| 1252 | c.Flags().BoolP("version", "v", false, usage) |
| 1253 | } else { |
| 1254 | c.Flags().Bool("version", false, usage) |
| 1255 | } |
| 1256 | _ = c.Flags().SetAnnotation("version", FlagSetByCobraAnnotation, []string{"true"}) |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | // InitDefaultHelpCmd adds default help command to c. |
| 1261 | // It is called automatically by executing the c or by calling help and usage. |
no test coverage detected