summaryrefslogtreecommitdiff
path: root/vendor/github.com/spf13/cobra/active_help.go
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2022-06-21 17:37:14 +0000
committerGitHub <noreply@github.com>2022-06-21 17:37:14 +0000
commitb8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661 (patch)
treeb20a2993e7c5cc5015476c65e15edb8b4bccf207 /vendor/github.com/spf13/cobra/active_help.go
parent588d8ec371202b5f6101c11f4c3e2952c2843d85 (diff)
parent050693b2e773e6334dc200fc0c819e3829ac400d (diff)
downloadpodman-b8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661.tar.gz
podman-b8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661.tar.bz2
podman-b8b0fa80454fe0f3bcdab24bbf17cf0b6c2e8661.zip
Merge pull request #14683 from Luap99/bump-cobra
bump github.com/spf13/cobra from 1.4.0 to 1.5.0
Diffstat (limited to 'vendor/github.com/spf13/cobra/active_help.go')
-rw-r--r--vendor/github.com/spf13/cobra/active_help.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/spf13/cobra/active_help.go b/vendor/github.com/spf13/cobra/active_help.go
new file mode 100644
index 000000000..0c631913d
--- /dev/null
+++ b/vendor/github.com/spf13/cobra/active_help.go
@@ -0,0 +1,49 @@
+package cobra
+
+import (
+ "fmt"
+ "os"
+ "strings"
+)
+
+const (
+ activeHelpMarker = "_activeHelp_ "
+ // The below values should not be changed: programs will be using them explicitly
+ // in their user documentation, and users will be using them explicitly.
+ activeHelpEnvVarSuffix = "_ACTIVE_HELP"
+ activeHelpGlobalEnvVar = "COBRA_ACTIVE_HELP"
+ activeHelpGlobalDisable = "0"
+)
+
+// AppendActiveHelp adds the specified string to the specified array to be used as ActiveHelp.
+// Such strings will be processed by the completion script and will be shown as ActiveHelp
+// to the user.
+// The array parameter should be the array that will contain the completions.
+// This function can be called multiple times before and/or after completions are added to
+// the array. Each time this function is called with the same array, the new
+// ActiveHelp line will be shown below the previous ones when completion is triggered.
+func AppendActiveHelp(compArray []string, activeHelpStr string) []string {
+ return append(compArray, fmt.Sprintf("%s%s", activeHelpMarker, activeHelpStr))
+}
+
+// GetActiveHelpConfig returns the value of the ActiveHelp environment variable
+// <PROGRAM>_ACTIVE_HELP where <PROGRAM> is the name of the root command in upper
+// case, with all - replaced by _.
+// It will always return "0" if the global environment variable COBRA_ACTIVE_HELP
+// is set to "0".
+func GetActiveHelpConfig(cmd *Command) string {
+ activeHelpCfg := os.Getenv(activeHelpGlobalEnvVar)
+ if activeHelpCfg != activeHelpGlobalDisable {
+ activeHelpCfg = os.Getenv(activeHelpEnvVar(cmd.Root().Name()))
+ }
+ return activeHelpCfg
+}
+
+// activeHelpEnvVar returns the name of the program-specific ActiveHelp environment
+// variable. It has the format <PROGRAM>_ACTIVE_HELP where <PROGRAM> is the name of the
+// root command in upper case, with all - replaced by _.
+func activeHelpEnvVar(name string) string {
+ // This format should not be changed: users will be using it explicitly.
+ activeHelpEnvVar := strings.ToUpper(fmt.Sprintf("%s%s", name, activeHelpEnvVarSuffix))
+ return strings.ReplaceAll(activeHelpEnvVar, "-", "_")
+}