From 7ba2df2eff4c859518addaa797466e74260a2d50 Mon Sep 17 00:00:00 2001 From: spf13 Date: Tue, 10 Sep 2013 18:28:58 -0400 Subject: [PATCH] Detect and panic if command is setup as it's own child. --- cobra.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cobra.go b/cobra.go index 2b9c16a..a7648d0 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) }