From d9a2a555d524f11a938f1c09086a1f497f52c491 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 23 Feb 2022 10:16:47 +0100 Subject: [PATCH] introduce plugin.RunningStandalone as utility func for a plugin to know it is run standalone Signed-off-by: Nicolas De Loof --- cli-plugins/plugin/plugin.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli-plugins/plugin/plugin.go b/cli-plugins/plugin/plugin.go index 0c3b1bf077..970e487e3c 100644 --- a/cli-plugins/plugin/plugin.go +++ b/cli-plugins/plugin/plugin.go @@ -160,3 +160,11 @@ func newMetadataSubcommand(plugin *cobra.Command, meta manager.Metadata) *cobra. } return cmd } + +// RunningStandalone tells a CLI plugin it is run standalone by direct execution +func RunningStandalone() bool { + if os.Getenv(manager.ReexecEnvvar) != "" { + return false + } + return len(os.Args) < 2 || os.Args[1] != manager.MetadataSubcommandName +}