Skip to content

Commit 39ee904

Browse files
authored
Merge pull request #3298 from crazy-max/cmd-fix-duplicated-usage
cmd: fix duplicated commands description
2 parents e3eb64e + b6cd86e commit 39ee904

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

commands/root.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/spf13/pflag"
2222
)
2323

24+
const experimentalCommandHint = `Experimental commands and flags are hidden. Set BUILDX_EXPERIMENTAL=1 to show them.`
25+
2426
func NewRootCmd(name string, isPlugin bool, dockerCli *command.DockerCli) *cobra.Command {
2527
var opt rootOptions
2628
cmd := &cobra.Command{
@@ -29,6 +31,12 @@ func NewRootCmd(name string, isPlugin bool, dockerCli *command.DockerCli) *cobra
2931
Use: name,
3032
Annotations: map[string]string{
3133
annotation.CodeDelimiter: `"`,
34+
"additionalHelp": func() string {
35+
if !confutil.IsExperimental() {
36+
return experimentalCommandHint
37+
}
38+
return ""
39+
}(),
3240
},
3341
CompletionOptions: cobra.CompletionOptions{
3442
HiddenDefaultCmd: true,
@@ -72,6 +80,9 @@ func NewRootCmd(name string, isPlugin bool, dockerCli *command.DockerCli) *cobra
7280
cmd.TraverseChildren = true
7381
cmd.DisableFlagsInUseLine = true
7482
cli.DisableFlagsInUseLine(cmd)
83+
if !confutil.IsExperimental() {
84+
cmd.SetHelpTemplate(cmd.HelpTemplate() + "\n" + experimentalCommandHint + "\n")
85+
}
7586
}
7687

7788
logrus.SetFormatter(&logutil.Formatter{})
@@ -84,10 +95,6 @@ func NewRootCmd(name string, isPlugin bool, dockerCli *command.DockerCli) *cobra
8495
"using default config store",
8596
))
8697

87-
if !confutil.IsExperimental() {
88-
cmd.SetHelpTemplate(cmd.HelpTemplate() + "\nExperimental commands and flags are hidden. Set BUILDX_EXPERIMENTAL=1 to show them.\n")
89-
}
90-
9198
addCommands(cmd, &opt, dockerCli)
9299
return cmd
93100
}

0 commit comments

Comments
 (0)