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

Method RemoveCommand

command.go:1401–1432  ·  view source on GitHub ↗

RemoveCommand removes one or more commands from a parent command.

(cmds ...*Command)

Source from the content-addressed store, hash-verified

1399
1400// RemoveCommand removes one or more commands from a parent command.
1401func (c *Command) RemoveCommand(cmds ...*Command) {
1402 commands := []*Command{}
1403main:
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.
1435func (c *Command) Print(i ...interface{}) {

Callers 7

initCompleteCmdMethod · 0.95
TestRemoveCommandFunction · 0.95
InitDefaultHelpCmdMethod · 0.95
getCompletionsMethod · 0.80
removeCompCmdFunction · 0.80

Calls 2

CommandPathMethod · 0.80
NameMethod · 0.80

Tested by 3

TestRemoveCommandFunction · 0.76
removeCompCmdFunction · 0.64