mirror of
https://github.com/spf13/cobra
synced 2024-11-05 05:17:12 +00:00
Detect and panic if command is setup as it's own child.
This commit is contained in:
parent
90b975fd8e
commit
7ba2df2eff
1 changed files with 3 additions and 0 deletions
3
cobra.go
3
cobra.go
|
@ -158,6 +158,9 @@ func (c *Command) ResetCommands() {
|
||||||
// Add one or many commands as children of this
|
// Add one or many commands as children of this
|
||||||
func (c *Command) AddCommand(cmds ...*Command) {
|
func (c *Command) AddCommand(cmds ...*Command) {
|
||||||
for i, x := range cmds {
|
for i, x := range cmds {
|
||||||
|
if cmds[i] == c {
|
||||||
|
panic("Command can't be a child of itself")
|
||||||
|
}
|
||||||
cmds[i].parent = c
|
cmds[i].parent = c
|
||||||
c.commands = append(c.commands, x)
|
c.commands = append(c.commands, x)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue