RemoveCommand removes one or more commands from a parent command.
(cmds ...*Command)
| 1399 | |
| 1400 | // RemoveCommand removes one or more commands from a parent command. |
| 1401 | func (c *Command) RemoveCommand(cmds ...*Command) { |
| 1402 | commands := []*Command{} |
| 1403 | main: |
| 1404 | for _, command := range c.commands { |
| 1405 | for _, cmd := range cmds { |
| 1406 | if command == cmd { |
| 1407 | command.parent = nil |
| 1408 | continue main |
| 1409 | } |
| 1410 | } |
| 1411 | commands = append(commands, command) |
| 1412 | } |
| 1413 | c.commands = commands |
| 1414 | // recompute all lengths |
| 1415 | c.commandsMaxUseLen = 0 |
| 1416 | c.commandsMaxCommandPathLen = 0 |
| 1417 | c.commandsMaxNameLen = 0 |
| 1418 | for _, command := range c.commands { |
| 1419 | usageLen := len(command.Use) |
| 1420 | if usageLen > c.commandsMaxUseLen { |
| 1421 | c.commandsMaxUseLen = usageLen |
| 1422 | } |
| 1423 | commandPathLen := len(command.CommandPath()) |
| 1424 | if commandPathLen > c.commandsMaxCommandPathLen { |
| 1425 | c.commandsMaxCommandPathLen = commandPathLen |
| 1426 | } |
| 1427 | nameLen := len(command.Name()) |
| 1428 | if nameLen > c.commandsMaxNameLen { |
| 1429 | c.commandsMaxNameLen = nameLen |
| 1430 | } |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | // Print is a convenience method to Print to the defined output, fallback to Stderr if not set. |
| 1435 | func (c *Command) Print(i ...interface{}) { |