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

Method AddCommand

command.go:1342–1368  ·  command.go::Command.AddCommand

AddCommand adds one or more commands to this parent command.

(cmds ...*Command)

Source from the content-addressed store, hash-verified

1340
1341// AddCommand adds one or more commands to this parent command.
1342func (c *Command) AddCommand(cmds ...*Command) {
1343 for i, x := range cmds {
1344 if cmds[i] == c {
1345 panic("Command can't be a child of itself")
1346 }
1347 cmds[i].parent = c
1348 // update max lengths
1349 usageLen := len(x.Use)
1350 if usageLen > c.commandsMaxUseLen {
1351 c.commandsMaxUseLen = usageLen
1352 }
1353 commandPathLen := len(x.CommandPath())
1354 if commandPathLen > c.commandsMaxCommandPathLen {
1355 c.commandsMaxCommandPathLen = commandPathLen
1356 }
1357 nameLen := len(x.Name())
1358 if nameLen > c.commandsMaxNameLen {
1359 c.commandsMaxNameLen = nameLen
1360 }
1361 // If global normalization function exists, update all children
1362 if c.globNormFunc != nil {
1363 x.SetGlobalNormalizationFunc(c.globNormFunc)
1364 }
1365 c.commands = append(c.commands, x)
1366 c.commandsAreSorted = false
1367 }
1368}
1369
1370// Groups returns a slice of child command groups.
1371func (c *Command) Groups() []*Group {

Callers 15

TestRootTakesNoArgsFunction · 0.95
TestRootTakesArgsFunction · 0.95
TestChildTakesNoArgsFunction · 0.95
TestChildTakesArgsFunction · 0.95
TestValidateFlagGroupsFunction · 0.95
TestActiveHelpAloneFunction · 0.95
TestActiveHelpWithCompsFunction · 0.95

Calls 3

CommandPathMethod · 0.80
NameMethod · 0.80

Tested by 15

TestRootTakesNoArgsFunction · 0.76
TestRootTakesArgsFunction · 0.76
TestChildTakesNoArgsFunction · 0.76
TestChildTakesArgsFunction · 0.76
TestValidateFlagGroupsFunction · 0.76
TestActiveHelpAloneFunction · 0.76
TestActiveHelpWithCompsFunction · 0.76