File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ func SetupRootCommand(rootCmd *cobra.Command) {
1717 cobra .AddTemplateFunc ("operationSubCommands" , operationSubCommands )
1818 cobra .AddTemplateFunc ("managementSubCommands" , managementSubCommands )
1919 cobra .AddTemplateFunc ("wrappedFlagUsages" , wrappedFlagUsages )
20+ cobra .AddTemplateFunc ("useLine" , UseLine )
2021
2122 rootCmd .SetUsageTemplate (usageTemplate )
2223 rootCmd .SetHelpTemplate (helpTemplate )
@@ -97,9 +98,19 @@ func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
9798 return cmds
9899}
99100
101+ // UseLine returns the usage line for a command. This implementation is different
102+ // from the default Command.UseLine in that it does not add a `[flags]` to the
103+ // of the line.
104+ func UseLine (cmd * cobra.Command ) string {
105+ if cmd .HasParent () {
106+ return cmd .Parent ().CommandPath () + " " + cmd .Use
107+ }
108+ return cmd .Use
109+ }
110+
100111var usageTemplate = `Usage:
101112
102- {{- if not .HasSubCommands}} {{.UseLine }}{{end}}
113+ {{- if not .HasSubCommands}} {{ useLine . }}{{end}}
103114{{- if .HasSubCommands}} {{ .CommandPath}} COMMAND{{end}}
104115
105116{{ .Short | trim }}
Original file line number Diff line number Diff line change 88 "sort"
99 "strings"
1010
11+ "github.com/docker/cli/cli"
1112 "github.com/spf13/cobra"
1213 "github.com/spf13/pflag"
1314 yaml "gopkg.in/yaml.v2"
@@ -92,7 +93,7 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer) error {
9293 }
9394
9495 if cmd .Runnable () {
95- cliDoc .Usage = cmd .UseLine ()
96+ cliDoc .Usage = cli .UseLine (cmd )
9697 }
9798
9899 if len (cmd .Example ) > 0 {
You can’t perform that action at this time.
0 commit comments