From 5aa293cc04221f8e0b3978e454140d3d70c9280f Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Wed, 3 Nov 2021 15:22:52 +0100 Subject: [PATCH] Fix plugin command delegation Signed-off-by: Ulysses Souza --- cli/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/main.go b/cli/main.go index 90baeab25..e3ce87cfa 100644 --- a/cli/main.go +++ b/cli/main.go @@ -101,12 +101,16 @@ func isContextAgnosticCommand(cmd *cobra.Command) bool { if cmd == nil { return false } - if _, ok := contextAgnosticCommands[cmd.Name()]; ok { + if _, ok := contextAgnosticCommands[cmd.Name()]; ok && isFirstLevelCommand(cmd) { return true } return isContextAgnosticCommand(cmd.Parent()) } +func isFirstLevelCommand(cmd *cobra.Command) bool { + return !cmd.HasParent() || !cmd.Parent().HasParent() +} + func main() { var opts cliopts.GlobalOpts root := &cobra.Command{