Detect and panic if command is setup as it's own child.
This commit is contained in:
parent
90b975fd8e
commit
7ba2df2eff
3
cobra.go
3
cobra.go
@ -158,6 +158,9 @@ func (c *Command) ResetCommands() {
|
||||
// Add one or many commands as children of this
|
||||
func (c *Command) AddCommand(cmds ...*Command) {
|
||||
for i, x := range cmds {
|
||||
if cmds[i] == c {
|
||||
panic("Command can't be a child of itself")
|
||||
}
|
||||
cmds[i].parent = c
|
||||
c.commands = append(c.commands, x)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user