This repository was archived by the owner on Jul 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,21 +63,31 @@ func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
6363 )
6464
6565 if ! dockerCli .ClientInfo ().HasExperimental {
66- hideExperimentalCLI (cmd )
66+ removeExperimentalCmdsAndFlags (cmd )
6767 }
6868}
6969
70- func hideExperimentalCLI (cmd * cobra.Command ) {
71- if _ , ok := cmd .Annotations ["experimentalCLI" ]; ok {
72- cmd .Hidden = true
73- }
70+ func removeExperimentalCmdsAndFlags (cmd * cobra.Command ) {
71+ enabledFlags := []* pflag.Flag {}
7472 cmd .Flags ().VisitAll (func (f * pflag.Flag ) {
75- if _ , ok := f .Annotations ["experimentalCLI" ]; ok {
76- f . Hidden = true
73+ if _ , disabled := f .Annotations ["experimentalCLI" ]; ! disabled {
74+ enabledFlags = append ( enabledFlags , f )
7775 }
7876 })
77+
78+ if len (enabledFlags ) != cmd .Flags ().NFlag () {
79+ cmd .ResetFlags ()
80+ for _ , f := range enabledFlags {
81+ cmd .Flags ().AddFlag (f )
82+ }
83+ }
84+
7985 for _ , subcmd := range cmd .Commands () {
80- hideExperimentalCLI (subcmd )
86+ if _ , ok := subcmd .Annotations ["experimentalCLI" ]; ok {
87+ cmd .RemoveCommand (subcmd )
88+ } else {
89+ removeExperimentalCmdsAndFlags (subcmd )
90+ }
8191 }
8292}
8393
You can’t perform that action at this time.
0 commit comments