summaryrefslogtreecommitdiff
path: root/vendor/github.com/smallstep/cli-utils/command/command.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/smallstep/cli-utils/command/command.go')
-rw-r--r--vendor/github.com/smallstep/cli-utils/command/command.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/github.com/smallstep/cli-utils/command/command.go b/vendor/github.com/smallstep/cli-utils/command/command.go
new file mode 100644
index 0000000..5da6e85
--- /dev/null
+++ b/vendor/github.com/smallstep/cli-utils/command/command.go
@@ -0,0 +1,45 @@
+package command
+
+import (
+ "os"
+
+ "github.com/urfave/cli"
+
+ "github.com/smallstep/cli-utils/step"
+ "github.com/smallstep/cli-utils/usage"
+)
+
+var cmds []cli.Command
+var currentContext *cli.Context
+
+func init() {
+ os.Unsetenv(step.IgnoreEnvVar)
+ cmds = []cli.Command{
+ usage.HelpCommand(),
+ }
+}
+
+// Register adds the given command to the global list of commands.
+// It sets recursively the command Flags environment variables.
+func Register(c cli.Command) {
+ step.SetEnvVar(&c)
+ cmds = append(cmds, c)
+}
+
+// Retrieve returns all commands
+func Retrieve() []cli.Command {
+ return cmds
+}
+
+// ActionFunc returns a cli.ActionFunc that stores the context.
+func ActionFunc(fn cli.ActionFunc) cli.ActionFunc {
+ return func(ctx *cli.Context) error {
+ currentContext = ctx
+ return fn(ctx)
+ }
+}
+
+// IsForce returns if the force flag was passed
+func IsForce() bool {
+ return currentContext != nil && currentContext.Bool("force")
+}