add check to NewCmdExec before printing suggestion

checks that the "describe" command and a parent command path exist
before printing suggestion to use the describe command to list
containers in a pod.
This commit is contained in:
juanvallejo
2016-09-28 12:41:42 -04:00
parent 48370b2802
commit 0988f967f0
4 changed files with 35 additions and 14 deletions

View File

@@ -716,3 +716,15 @@ func ObjectListToVersionedObject(objects []runtime.Object, version unversioned.G
}
return converted, nil
}
// IsSiblingCommandExists receives a pointer to a cobra command and a target string.
// Returns true if the target string is found in the list of sibling commands.
func IsSiblingCommandExists(cmd *cobra.Command, targetCmdName string) bool {
for _, c := range cmd.Parent().Commands() {
if c.Name() == targetCmdName {
return true
}
}
return false
}