diff --git a/cobra.go b/cobra.go index 2b9c16a9..a7648d08 100644 --- a/cobra.go +++ b/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) }