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

Method InitDefaultVersionFlag

command.go:1238–1258  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

1236// If c already has a version flag, it will do nothing.
1237// If c.Version is empty, it will do nothing.
1238func (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.

Callers 3

getCompletionsMethod · 0.95
executeMethod · 0.95
InitDefaultHelpCmdMethod · 0.80

Calls 4

mergePersistentFlagsMethod · 0.95
FlagsMethod · 0.95
NameMethod · 0.95
DisplayNameMethod · 0.95

Tested by

no test coverage detected