-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathcommands.go
More file actions
39 lines (33 loc) · 1.16 KB
/
commands.go
File metadata and controls
39 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package commands
import (
"os"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
)
var commands []func(command.Cli) *cobra.Command
// Register pushes the passed in command into an internal queue which can
// be retrieved using the [Commands] function. It is designed to be called
// in an init function and is not safe for concurrent use.
func Register(f func(command.Cli) *cobra.Command) {
commands = append(commands, f)
}
// RegisterLegacy functions similarly to [Register], but it checks the
// "DOCKER_HIDE_LEGACY_COMMANDS" environment variable and if it has been
// set and is non-empty, the command will be hidden. It is designed to be called
// in an init function and is not safe for concurrent use.
func RegisterLegacy(f func(command.Cli) *cobra.Command) {
commands = append(commands, func(c command.Cli) *cobra.Command {
if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" {
return f(c)
}
cmd := f(c)
cmd.Hidden = true
cmd.Aliases = []string{}
return cmd
})
}
// Commands returns the internal queue holding registered commands added
// via [Register] and [RegisterLegacy].
func Commands() []func(command.Cli) *cobra.Command {
return commands
}