Browse Source

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 <[email protected]>
Pierre Roux 3 năm trước cách đây
mục cha
commit
38a18790ed

+ 1 - 0
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].")

+ 2 - 2
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)
 		}),

+ 1 - 1
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

+ 1 - 1
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 |

+ 2 - 2
docs/reference/compose_restart.md

@@ -1,7 +1,7 @@
 # docker compose restart
 
 <!---MARKER_GEN_START-->
-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

+ 3 - 3
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: