Skip to content

Commit 8e600e1

Browse files
committed
Fix UseLine
Signed-off-by: Daniel Nephin <dnephin@docker.com>
1 parent 4205416 commit 8e600e1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

‎cli/cobra.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
100111
var 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 }}

‎docs/yaml/yaml.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
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 {

0 commit comments

Comments
 (0)