Skip to content

Commit ed374b4

Browse files
committed
move orchestration commands to their own section in --help output
This groups all swarm-related subcommands to their own section in the --help output, to make it clearer which commands require swarm to be enabled With this change: Usage: docker [OPTIONS] COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/Users/sebastiaan/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/Users/sebastiaan/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/Users/sebastiaan/.docker/cert.pem") --tlskey string Path to TLS key file (default "/Users/sebastiaan/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: builder Manage builds buildx* Docker Buildx (Docker Inc., v0.8.1) checkpoint Manage checkpoints completion Generate the autocompletion script for the specified shell compose* Docker Compose (Docker Inc., v2.3.3) container Manage containers context Manage contexts image Manage images manifest Manage Docker image manifests and manifest lists network Manage networks plugin Manage plugins scan* Docker Scan (Docker Inc., v0.17.0) system Manage Docker trust Manage trust on Docker images volume Manage volumes Orchestration Commands: config Manage Swarm configs node Manage Swarm nodes secret Manage Swarm secrets service Manage Swarm services stack Manage Swarm stacks swarm Manage Swarm Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command. To get more help with docker, check out our guides at https://docs.docker.com/go/guides/ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 174e51c commit ed374b4

9 files changed

Lines changed: 45 additions & 9 deletions

File tree

cli/cobra.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ func setupCommonRootCommand(rootCmd *cobra.Command) (*cliflags.ClientOptions, *p
3131
cobra.AddTemplateFunc("add", func(a, b int) int { return a + b })
3232
cobra.AddTemplateFunc("hasSubCommands", hasSubCommands)
3333
cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands)
34+
cobra.AddTemplateFunc("hasOrchestratorSubCommands", hasOrchestratorSubCommands)
3435
cobra.AddTemplateFunc("hasInvalidPlugins", hasInvalidPlugins)
3536
cobra.AddTemplateFunc("operationSubCommands", operationSubCommands)
3637
cobra.AddTemplateFunc("managementSubCommands", managementSubCommands)
38+
cobra.AddTemplateFunc("orchestratorSubCommands", orchestratorSubCommands)
3739
cobra.AddTemplateFunc("invalidPlugins", invalidPlugins)
3840
cobra.AddTemplateFunc("wrappedFlagUsages", wrappedFlagUsages)
3941
cobra.AddTemplateFunc("vendorAndVersion", vendorAndVersion)
@@ -240,6 +242,10 @@ func hasManagementSubCommands(cmd *cobra.Command) bool {
240242
return len(managementSubCommands(cmd)) > 0
241243
}
242244

245+
func hasOrchestratorSubCommands(cmd *cobra.Command) bool {
246+
return len(orchestratorSubCommands(cmd)) > 0
247+
}
248+
243249
func hasInvalidPlugins(cmd *cobra.Command) bool {
244250
return len(invalidPlugins(cmd)) > 0
245251
}
@@ -285,6 +291,27 @@ func vendorAndVersion(cmd *cobra.Command) string {
285291
}
286292

287293
func managementSubCommands(cmd *cobra.Command) []*cobra.Command {
294+
cmds := []*cobra.Command{}
295+
for _, sub := range allManagementSubCommands(cmd) {
296+
if _, ok := sub.Annotations["swarm"]; ok {
297+
continue
298+
}
299+
cmds = append(cmds, sub)
300+
}
301+
return cmds
302+
}
303+
304+
func orchestratorSubCommands(cmd *cobra.Command) []*cobra.Command {
305+
cmds := []*cobra.Command{}
306+
for _, sub := range allManagementSubCommands(cmd) {
307+
if _, ok := sub.Annotations["swarm"]; ok {
308+
cmds = append(cmds, sub)
309+
}
310+
}
311+
return cmds
312+
}
313+
314+
func allManagementSubCommands(cmd *cobra.Command) []*cobra.Command {
288315
cmds := []*cobra.Command{}
289316
for _, sub := range cmd.Commands() {
290317
if isPlugin(sub) {
@@ -359,6 +386,15 @@ Management Commands:
359386
{{rpad (decoratedName .) (add .NamePadding 1)}}{{.Short}}{{ if isPlugin .}} {{vendorAndVersion .}}{{ end}}
360387
{{- end}}
361388
389+
{{- end}}
390+
{{- if hasOrchestratorSubCommands . }}
391+
392+
Orchestration Commands:
393+
394+
{{- range orchestratorSubCommands . }}
395+
{{rpad (decoratedName .) (add .NamePadding 1)}}{{.Short}}{{ if isPlugin .}} {{vendorAndVersion .}}{{ end}}
396+
{{- end}}
397+
362398
{{- end}}
363399
{{- if hasSubCommands .}}
364400

cli/command/config/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func NewConfigCommand(dockerCli command.Cli) *cobra.Command {
1212
cmd := &cobra.Command{
1313
Use: "config",
14-
Short: "Manage Docker configs",
14+
Short: "Manage Swarm configs",
1515
Args: cli.NoArgs,
1616
RunE: command.ShowHelp(dockerCli.Err()),
1717
Annotations: map[string]string{

cli/command/secret/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func NewSecretCommand(dockerCli command.Cli) *cobra.Command {
1212
cmd := &cobra.Command{
1313
Use: "secret",
14-
Short: "Manage Docker secrets",
14+
Short: "Manage Swarm secrets",
1515
Args: cli.NoArgs,
1616
RunE: command.ShowHelp(dockerCli.Err()),
1717
Annotations: map[string]string{

cli/command/service/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func NewServiceCommand(dockerCli command.Cli) *cobra.Command {
1212
cmd := &cobra.Command{
1313
Use: "service",
14-
Short: "Manage services",
14+
Short: "Manage Swarm services",
1515
Args: cli.NoArgs,
1616
RunE: command.ShowHelp(dockerCli.Err()),
1717
Annotations: map[string]string{

cli/command/stack/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func NewStackCommand(dockerCli command.Cli) *cobra.Command {
1313
cmd := &cobra.Command{
1414
Use: "stack [OPTIONS]",
15-
Short: "Manage Docker stacks",
15+
Short: "Manage Swarm stacks",
1616
Args: cli.NoArgs,
1717
RunE: command.ShowHelp(dockerCli.Err()),
1818
Annotations: map[string]string{

docs/reference/commandline/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords: "config"
99
```markdown
1010
Usage: docker config COMMAND
1111

12-
Manage Docker configs
12+
Manage Swarm configs
1313

1414
Options:
1515
--help Print usage

docs/reference/commandline/secret.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords: "secret"
99
```markdown
1010
Usage: docker secret COMMAND
1111

12-
Manage Docker secrets
12+
Manage Swarm secrets
1313

1414
Options:
1515
--help Print usage

docs/reference/commandline/service.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords: "service"
99
```markdown
1010
Usage: docker service COMMAND
1111

12-
Manage services
12+
Manage Swarm services
1313

1414
Options:
1515
--help Print usage
@@ -29,7 +29,7 @@ Run 'docker service COMMAND --help' for more information on a command.
2929

3030
## Description
3131

32-
Manage services.
32+
Manage Swarm services.
3333

3434
> **Note**
3535
>

docs/reference/commandline/stack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords: "stack"
99
```markdown
1010
Usage: docker stack [OPTIONS] COMMAND
1111

12-
Manage Docker stacks
12+
Manage Swarm stacks
1313

1414
Options:
1515
--help Print usage

0 commit comments

Comments
 (0)