浏览代码

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 年之前
父节点
当前提交
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 {
 		RunE: Adapt(func(ctx context.Context, args []string) error {
 			return runList(ctx, backend, lsOpts)
 			return runList(ctx, backend, lsOpts)
 		}),
 		}),
+		Args:              cobra.NoArgs,
 		ValidArgsFunction: noCompletion(),
 		ValidArgsFunction: noCompletion(),
 	}
 	}
 	lsCmd.Flags().StringVar(&lsOpts.Format, "format", "pretty", "Format the output. Values: [pretty | json].")
 	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,
 		projectOptions: p,
 	}
 	}
 	restartCmd := &cobra.Command{
 	restartCmd := &cobra.Command{
-		Use:   "restart",
-		Short: "Restart containers",
+		Use:   "restart [SERVICE...]",
+		Short: "Restart service containers",
 		RunE: Adapt(func(ctx context.Context, args []string) error {
 		RunE: Adapt(func(ctx context.Context, args []string) error {
 			return runRestart(ctx, backend, opts, args)
 			return runRestart(ctx, backend, opts, args)
 		}),
 		}),

+ 1 - 1
cmd/compose/version.go

@@ -37,7 +37,7 @@ func versionCommand() *cobra.Command {
 	cmd := &cobra.Command{
 	cmd := &cobra.Command{
 		Use:   "version",
 		Use:   "version",
 		Short: "Show the Docker Compose version information",
 		Short: "Show the Docker Compose version information",
-		Args:  cobra.MaximumNArgs(0),
+		Args:  cobra.NoArgs,
 		RunE: func(cmd *cobra.Command, _ []string) error {
 		RunE: func(cmd *cobra.Command, _ []string) error {
 			runVersion(opts)
 			runVersion(opts)
 			return nil
 			return nil

+ 1 - 1
docs/reference/compose.md

@@ -23,7 +23,7 @@ Docker Compose
 | [`ps`](compose_ps.md) | List containers |
 | [`ps`](compose_ps.md) | List containers |
 | [`pull`](compose_pull.md) | Pull service images |
 | [`pull`](compose_pull.md) | Pull service images |
 | [`push`](compose_push.md) | Push 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 |
 | [`rm`](compose_rm.md) | Removes stopped service containers |
 | [`run`](compose_run.md) | Run a one-off command on a service. |
 | [`run`](compose_run.md) | Run a one-off command on a service. |
 | [`start`](compose_start.md) | Start services |
 | [`start`](compose_start.md) | Start services |

+ 2 - 2
docs/reference/compose_restart.md

@@ -1,7 +1,7 @@
 # docker compose restart
 # docker compose restart
 
 
 <!---MARKER_GEN_START-->
 <!---MARKER_GEN_START-->
-Restart containers
+Restart service containers
 
 
 ### Options
 ### Options
 
 
@@ -14,7 +14,7 @@ Restart containers
 
 
 ## Description
 ## 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
 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
 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
 command: docker compose restart
-short: Restart containers
+short: Restart service containers
 long: |-
 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
     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
     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
     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)
     [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).
     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
 pname: docker compose
 plink: docker_compose.yaml
 plink: docker_compose.yaml
 options:
 options: