AddCommand adds one or more commands to this parent command.
(cmds ...*Command)
| 1340 | |
| 1341 | // AddCommand adds one or more commands to this parent command. |
| 1342 | func (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. |
| 1371 | func (c *Command) Groups() []*Group { |