From 38a18790ed19a335e6776dd5e39b7fa620e48a32 Mon Sep 17 00:00:00 2001 From: Pierre Roux Date: Fri, 29 Jul 2022 15:30:11 +0200 Subject: [PATCH] cmd: consistent handling no-args commands (#9660) Enforce args rejection for commands without args: * ls * version Additionally, docs for `restart` are fixed. Signed-off-by: piroux --- cmd/compose/list.go | 1 + cmd/compose/restart.go | 4 ++-- cmd/compose/version.go | 2 +- docs/reference/compose.md | 2 +- docs/reference/compose_restart.md | 4 ++-- docs/reference/docker_compose_restart.yaml | 6 +++--- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/compose/list.go b/cmd/compose/list.go index 618ad03c7..d4d53b726 100644 --- a/cmd/compose/list.go +++ b/cmd/compose/list.go @@ -46,6 +46,7 @@ func listCommand(backend api.Service) *cobra.Command { RunE: Adapt(func(ctx context.Context, args []string) error { return runList(ctx, backend, lsOpts) }), + Args: cobra.NoArgs, ValidArgsFunction: noCompletion(), } lsCmd.Flags().StringVar(&lsOpts.Format, "format", "pretty", "Format the output. Values: [pretty | json].") diff --git a/cmd/compose/restart.go b/cmd/compose/restart.go index f691c31fb..f09d6fc83 100644 --- a/cmd/compose/restart.go +++ b/cmd/compose/restart.go @@ -35,8 +35,8 @@ func restartCommand(p *projectOptions, backend api.Service) *cobra.Command { projectOptions: p, } restartCmd := &cobra.Command{ - Use: "restart", - Short: "Restart containers", + Use: "restart [SERVICE...]", + Short: "Restart service containers", RunE: Adapt(func(ctx context.Context, args []string) error { return runRestart(ctx, backend, opts, args) }), diff --git a/cmd/compose/version.go b/cmd/compose/version.go index 30e0e753e..06aff04d9 100644 --- a/cmd/compose/version.go +++ b/cmd/compose/version.go @@ -37,7 +37,7 @@ func versionCommand() *cobra.Command { cmd := &cobra.Command{ Use: "version", Short: "Show the Docker Compose version information", - Args: cobra.MaximumNArgs(0), + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { runVersion(opts) return nil diff --git a/docs/reference/compose.md b/docs/reference/compose.md index 46d3a1a72..e1b2c1fd0 100644 --- a/docs/reference/compose.md +++ b/docs/reference/compose.md @@ -23,7 +23,7 @@ Docker Compose | [`ps`](compose_ps.md) | List containers | | [`pull`](compose_pull.md) | Pull service images | | [`push`](compose_push.md) | Push service images | -| [`restart`](compose_restart.md) | Restart containers | +| [`restart`](compose_restart.md) | Restart service containers | | [`rm`](compose_rm.md) | Removes stopped service containers | | [`run`](compose_run.md) | Run a one-off command on a service. | | [`start`](compose_start.md) | Start services | diff --git a/docs/reference/compose_restart.md b/docs/reference/compose_restart.md index 12326662b..cc152b562 100644 --- a/docs/reference/compose_restart.md +++ b/docs/reference/compose_restart.md @@ -1,7 +1,7 @@ # docker compose restart -Restart containers +Restart service containers ### Options @@ -14,7 +14,7 @@ Restart containers ## Description -Restarts all stopped and running services. +Restarts all stopped and running services, or the specified services only. If you make changes to your `compose.yml` configuration, these changes are not reflected after running this command. For example, changes to environment variables (which are added diff --git a/docs/reference/docker_compose_restart.yaml b/docs/reference/docker_compose_restart.yaml index 8864aabdd..733c3b271 100644 --- a/docs/reference/docker_compose_restart.yaml +++ b/docs/reference/docker_compose_restart.yaml @@ -1,7 +1,7 @@ command: docker compose restart -short: Restart containers +short: Restart service containers long: |- - Restarts all stopped and running services. + Restarts all stopped and running services, or the specified services only. If you make changes to your `compose.yml` configuration, these changes are not reflected after running this command. For example, changes to environment variables (which are added @@ -11,7 +11,7 @@ long: |- If you are looking to configure a service's restart policy, please refer to [restart](https://github.com/compose-spec/compose-spec/blob/master/spec.md#restart) or [restart_policy](https://github.com/compose-spec/compose-spec/blob/master/deploy.md#restart_policy). -usage: docker compose restart +usage: docker compose restart [SERVICE...] pname: docker compose plink: docker_compose.yaml options: