Better formatting for usage template.
Group commands in usage to management/operation commands.
Remove the word Docker from the description of management commands.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -9,6 +9,11 @@ import ( |
| 9 | 9 |
// SetupRootCommand sets default usage, help, and error handling for the |
| 10 | 10 |
// root command. |
| 11 | 11 |
func SetupRootCommand(rootCmd *cobra.Command) {
|
| 12 |
+ cobra.AddTemplateFunc("hasSubCommands", hasSubCommands)
|
|
| 13 |
+ cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands)
|
|
| 14 |
+ cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
|
|
| 15 |
+ cobra.AddTemplateFunc("managementSubCommands", managementSubCommands)
|
|
| 16 |
+ |
|
| 12 | 17 |
rootCmd.SetUsageTemplate(usageTemplate) |
| 13 | 18 |
rootCmd.SetHelpTemplate(helpTemplate) |
| 14 | 19 |
rootCmd.SetFlagErrorFunc(FlagErrorFunc) |
| ... | ... |
@@ -34,23 +39,81 @@ func FlagErrorFunc(cmd *cobra.Command, err error) error {
|
| 34 | 34 |
} |
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
-var usageTemplate = `Usage: {{if not .HasSubCommands}}{{.UseLine}}{{end}}{{if .HasSubCommands}}{{ .CommandPath}} COMMAND{{end}}
|
|
| 37 |
+func hasSubCommands(cmd *cobra.Command) bool {
|
|
| 38 |
+ return len(operationSubCommands(cmd)) > 0 |
|
| 39 |
+} |
|
| 40 |
+ |
|
| 41 |
+func hasManagementSubCommands(cmd *cobra.Command) bool {
|
|
| 42 |
+ return len(managementSubCommands(cmd)) > 0 |
|
| 43 |
+} |
|
| 44 |
+ |
|
| 45 |
+func operationSubCommands(cmd *cobra.Command) []*cobra.Command {
|
|
| 46 |
+ cmds := []*cobra.Command{}
|
|
| 47 |
+ for _, sub := range cmd.Commands() {
|
|
| 48 |
+ if sub.IsAvailableCommand() && !sub.HasSubCommands() {
|
|
| 49 |
+ cmds = append(cmds, sub) |
|
| 50 |
+ } |
|
| 51 |
+ } |
|
| 52 |
+ return cmds |
|
| 53 |
+} |
|
| 54 |
+ |
|
| 55 |
+func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
|
|
| 56 |
+ cmds := []*cobra.Command{}
|
|
| 57 |
+ for _, sub := range cmd.Commands() {
|
|
| 58 |
+ if sub.IsAvailableCommand() && sub.HasSubCommands() {
|
|
| 59 |
+ cmds = append(cmds, sub) |
|
| 60 |
+ } |
|
| 61 |
+ } |
|
| 62 |
+ return cmds |
|
| 63 |
+} |
|
| 64 |
+ |
|
| 65 |
+var usageTemplate = `Usage: |
|
| 38 | 66 |
|
| 39 |
-{{ .Short | trim }}{{if gt .Aliases 0}}
|
|
| 67 |
+{{- if not .HasSubCommands}} {{.UseLine}}{{end}}
|
|
| 68 |
+{{- if .HasSubCommands}} {{ .CommandPath}} COMMAND{{end}}
|
|
| 69 |
+ |
|
| 70 |
+{{ .Short | trim }}
|
|
| 71 |
+ |
|
| 72 |
+{{- if gt .Aliases 0}}
|
|
| 40 | 73 |
|
| 41 | 74 |
Aliases: |
| 42 |
- {{.NameAndAliases}}{{end}}{{if .HasExample}}
|
|
| 75 |
+ {{.NameAndAliases}}
|
|
| 76 |
+ |
|
| 77 |
+{{- end}}
|
|
| 78 |
+{{- if .HasExample}}
|
|
| 43 | 79 |
|
| 44 | 80 |
Examples: |
| 45 |
-{{ .Example }}{{end}}{{if .HasFlags}}
|
|
| 81 |
+{{ .Example }}
|
|
| 82 |
+ |
|
| 83 |
+{{- end}}
|
|
| 84 |
+{{- if .HasFlags}}
|
|
| 46 | 85 |
|
| 47 | 86 |
Options: |
| 48 |
-{{.Flags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasAvailableSubCommands}}
|
|
| 87 |
+{{.Flags.FlagUsages | trimRightSpace}}
|
|
| 88 |
+ |
|
| 89 |
+{{- end}}
|
|
| 90 |
+{{- if hasManagementSubCommands . }}
|
|
| 91 |
+ |
|
| 92 |
+Management Commands: |
|
| 93 |
+ |
|
| 94 |
+{{- range managementSubCommands . }}
|
|
| 95 |
+ {{rpad .Name .NamePadding }} {{.Short}}
|
|
| 96 |
+{{- end}}
|
|
| 97 |
+ |
|
| 98 |
+{{- end}}
|
|
| 99 |
+{{- if hasSubCommands .}}
|
|
| 100 |
+ |
|
| 101 |
+Commands: |
|
| 102 |
+ |
|
| 103 |
+{{- range operationSubCommands . }}
|
|
| 104 |
+ {{rpad .Name .NamePadding }} {{.Short}}
|
|
| 105 |
+{{- end}}
|
|
| 106 |
+{{- end}}
|
|
| 49 | 107 |
|
| 50 |
-Commands:{{range .Commands}}{{if .IsAvailableCommand}}
|
|
| 51 |
- {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasSubCommands }}
|
|
| 108 |
+{{- if .HasSubCommands }}
|
|
| 52 | 109 |
|
| 53 |
-Run '{{.CommandPath}} COMMAND --help' for more information on a command.{{end}}
|
|
| 110 |
+Run '{{.CommandPath}} COMMAND --help' for more information on a command.
|
|
| 111 |
+{{- end}}
|
|
| 54 | 112 |
` |
| 55 | 113 |
|
| 56 | 114 |
var helpTemplate = ` |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
func NewCheckpointCommand(rootCmd *cobra.Command, dockerCli *command.DockerCli) {
|
| 16 | 16 |
cmd := &cobra.Command{
|
| 17 | 17 |
Use: "checkpoint", |
| 18 |
- Short: "Manage Container Checkpoints", |
|
| 18 |
+ Short: "Manage checkpoints", |
|
| 19 | 19 |
Args: cli.NoArgs, |
| 20 | 20 |
Run: func(cmd *cobra.Command, args []string) {
|
| 21 | 21 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -1,6 +1,8 @@ |
| 1 | 1 |
package commands |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "os" |
|
| 5 |
+ |
|
| 4 | 6 |
"github.com/docker/docker/cli/command" |
| 5 | 7 |
"github.com/docker/docker/cli/command/checkpoint" |
| 6 | 8 |
"github.com/docker/docker/cli/command/container" |
| ... | ... |
@@ -75,6 +77,9 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) {
|
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
func hide(cmd *cobra.Command) *cobra.Command {
|
| 78 |
+ if os.Getenv("DOCKER_HIDE_LEGACY_COMMANDS") == "" {
|
|
| 79 |
+ return cmd |
|
| 80 |
+ } |
|
| 78 | 81 |
cmdCopy := *cmd |
| 79 | 82 |
cmdCopy.Hidden = true |
| 80 | 83 |
cmdCopy.Aliases = []string{}
|
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
func NewContainerCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 14 | 14 |
cmd := &cobra.Command{
|
| 15 | 15 |
Use: "container", |
| 16 |
- Short: "Manage Docker containers", |
|
| 16 |
+ Short: "Manage containers", |
|
| 17 | 17 |
Args: cli.NoArgs, |
| 18 | 18 |
Run: func(cmd *cobra.Command, args []string) {
|
| 19 | 19 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 14 | 14 |
cmd := &cobra.Command{
|
| 15 | 15 |
Use: "image", |
| 16 |
- Short: "Manage Docker images", |
|
| 16 |
+ Short: "Manage images", |
|
| 17 | 17 |
Args: cli.NoArgs, |
| 18 | 18 |
Run: func(cmd *cobra.Command, args []string) {
|
| 19 | 19 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
func NewNetworkCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 14 | 14 |
cmd := &cobra.Command{
|
| 15 | 15 |
Use: "network", |
| 16 |
- Short: "Manage Docker networks", |
|
| 16 |
+ Short: "Manage networks", |
|
| 17 | 17 |
Args: cli.NoArgs, |
| 18 | 18 |
Run: func(cmd *cobra.Command, args []string) {
|
| 19 | 19 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 15 | 15 |
cmd := &cobra.Command{
|
| 16 | 16 |
Use: "node", |
| 17 |
- Short: "Manage Docker Swarm nodes", |
|
| 17 |
+ Short: "Manage Swarm nodes", |
|
| 18 | 18 |
Args: cli.NoArgs, |
| 19 | 19 |
Run: func(cmd *cobra.Command, args []string) {
|
| 20 | 20 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
func NewPluginCommand(rootCmd *cobra.Command, dockerCli *command.DockerCli) {
|
| 15 | 15 |
cmd := &cobra.Command{
|
| 16 | 16 |
Use: "plugin", |
| 17 |
- Short: "Manage Docker plugins", |
|
| 17 |
+ Short: "Manage plugins", |
|
| 18 | 18 |
Args: cli.NoArgs, |
| 19 | 19 |
Run: func(cmd *cobra.Command, args []string) {
|
| 20 | 20 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 14 | 14 |
cmd := &cobra.Command{
|
| 15 | 15 |
Use: "service", |
| 16 |
- Short: "Manage Docker services", |
|
| 16 |
+ Short: "Manage services", |
|
| 17 | 17 |
Args: cli.NoArgs, |
| 18 | 18 |
Run: func(cmd *cobra.Command, args []string) {
|
| 19 | 19 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 15 | 15 |
cmd := &cobra.Command{
|
| 16 | 16 |
Use: "stack", |
| 17 |
- Short: "Manage Docker stacks", |
|
| 17 |
+ Short: "Manage stacks", |
|
| 18 | 18 |
Args: cli.NoArgs, |
| 19 | 19 |
Run: func(cmd *cobra.Command, args []string) {
|
| 20 | 20 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
func NewSwarmCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 14 | 14 |
cmd := &cobra.Command{
|
| 15 | 15 |
Use: "swarm", |
| 16 |
- Short: "Manage Docker Swarm", |
|
| 16 |
+ Short: "Manage Swarm", |
|
| 17 | 17 |
Args: cli.NoArgs, |
| 18 | 18 |
Run: func(cmd *cobra.Command, args []string) {
|
| 19 | 19 |
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
func NewVolumeCommand(dockerCli *command.DockerCli) *cobra.Command {
|
| 14 | 14 |
cmd := &cobra.Command{
|
| 15 | 15 |
Use: "volume COMMAND", |
| 16 |
- Short: "Manage Docker volumes", |
|
| 16 |
+ Short: "Manage volumes", |
|
| 17 | 17 |
Long: volumeDescription, |
| 18 | 18 |
Args: cli.NoArgs, |
| 19 | 19 |
Run: func(cmd *cobra.Command, args []string) {
|