File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-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 Register (f func (command.Cli ) * cobra.Command ) {
18+ l .Lock ()
19+ defer l .Unlock ()
20+ commands = append (commands , f )
21+ }
22+
23+ // RegisterLegacy checks the `DOCKER_HIDE_LEGACY_COMMANDS` environment variable and if
24+ // it has been set and is non-empty, the command will be hidden.
25+ func RegisterLegacy (f func (command.Cli ) * cobra.Command ) {
26+ l .Lock ()
27+ defer l .Unlock ()
28+ commands = append (commands , func (c command.Cli ) * cobra.Command {
29+ cmd := f (c )
30+ if os .Getenv ("DOCKER_HIDE_LEGACY_COMMANDS" ) == "" {
31+ return cmd
32+ }
33+ cmdCopy := * cmd
34+ cmdCopy .Hidden = true
35+ cmdCopy .Aliases = []string {}
36+ return & cmdCopy
37+ })
38+ }
39+
40+ func Commands () []func (command.Cli ) * cobra.Command {
41+ l .RLock ()
42+ defer l .RUnlock ()
43+ return slices .Clone (commands )
44+ }
You can’t perform that action at this time.
0 commit comments