File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ package commands
2+
3+ import (
4+ "os"
5+ "slices"
6+ "sync"
7+
8+ "github.com/docker/cli/cli/command"
9+ "github.com/spf13/cobra"
10+ )
11+
12+ var (
13+ commands []func (command.Cli ) * cobra.Command
14+ l sync.RWMutex
15+ )
16+
17+ func RegisterCommand (f func (command.Cli ) * cobra.Command ) {
18+ l .Lock ()
19+ defer l .Unlock ()
20+ commands = append (commands , f )
21+ }
22+
23+ // MaybeHideLegacy checks the `DOCKER_HIDE_LEGACY_COMMANDS` environment variable and if
24+ // it has been set and is non-empty, the legacy command will be hidden.
25+ // Legacy commands are `docker ps`, `docker exec`, etc.
26+ func MaybeHideLegacy (f func (command.Cli ) * cobra.Command ) func (command.Cli ) * cobra.Command {
27+ return func (c command.Cli ) * cobra.Command {
28+ cmd := f (c )
29+ // If the environment variable with name "DOCKER_HIDE_LEGACY_COMMANDS" is not empty,
30+ // these legacy commands (such as `docker ps`, `docker exec`, etc)
31+ // will not be shown in output console.
32+ if os .Getenv ("DOCKER_HIDE_LEGACY_COMMANDS" ) == "" {
33+ return cmd
34+ }
35+ cmdCopy := * cmd
36+ cmdCopy .Hidden = true
37+ cmdCopy .Aliases = []string {}
38+ return & cmdCopy
39+ }
40+ }
41+
42+ func Commands () []func (command.Cli ) * cobra.Command {
43+ l .RLock ()
44+ defer l .RUnlock ()
45+ return slices .Clone (commands )
46+ }
You can’t perform that action at this time.
0 commit comments