Skip to content

Commit 38a1879

Browse files
authored
cmd: consistent handling no-args commands (docker#9660)
Enforce args rejection for commands without args: * ls * version Additionally, docs for `restart` are fixed. Signed-off-by: piroux <[email protected]>
1 parent def189f commit 38a1879

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

cmd/compose/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func listCommand(backend api.Service) *cobra.Command {
4646
RunE: Adapt(func(ctx context.Context, args []string) error {
4747
return runList(ctx, backend, lsOpts)
4848
}),
49+
Args: cobra.NoArgs,
4950
ValidArgsFunction: noCompletion(),
5051
}
5152
lsCmd.Flags().StringVar(&lsOpts.Format, "format", "pretty", "Format the output. Values: [pretty | json].")

cmd/compose/restart.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func restartCommand(p *projectOptions, backend api.Service) *cobra.Command {
3535
projectOptions: p,
3636
}
3737
restartCmd := &cobra.Command{
38-
Use: "restart",
39-
Short: "Restart containers",
38+
Use: "restart [SERVICE...]",
39+
Short: "Restart service containers",
4040
RunE: Adapt(func(ctx context.Context, args []string) error {
4141
return runRestart(ctx, backend, opts, args)
4242
}),

cmd/compose/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func versionCommand() *cobra.Command {
3737
cmd := &cobra.Command{
3838
Use: "version",
3939
Short: "Show the Docker Compose version information",
40-
Args: cobra.MaximumNArgs(0),
40+
Args: cobra.NoArgs,
4141
RunE: func(cmd *cobra.Command, _ []string) error {
4242
runVersion(opts)
4343
return nil

docs/reference/compose.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Docker Compose
2323
| [`ps`](compose_ps.md) | List containers |
2424
| [`pull`](compose_pull.md) | Pull service images |
2525
| [`push`](compose_push.md) | Push service images |
26-
| [`restart`](compose_restart.md) | Restart containers |
26+
| [`restart`](compose_restart.md) | Restart service containers |
2727
| [`rm`](compose_rm.md) | Removes stopped service containers |
2828
| [`run`](compose_run.md) | Run a one-off command on a service. |
2929
| [`start`](compose_start.md) | Start services |

docs/reference/compose_restart.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# docker compose restart
22

33
<!---MARKER_GEN_START-->
4-
Restart containers
4+
Restart service containers
55

66
### Options
77

@@ -14,7 +14,7 @@ Restart containers
1414

1515
## Description
1616

17-
Restarts all stopped and running services.
17+
Restarts all stopped and running services, or the specified services only.
1818

1919
If you make changes to your `compose.yml` configuration, these changes are not reflected
2020
after running this command. For example, changes to environment variables (which are added

docs/reference/docker_compose_restart.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
command: docker compose restart
2-
short: Restart containers
2+
short: Restart service containers
33
long: |-
4-
Restarts all stopped and running services.
4+
Restarts all stopped and running services, or the specified services only.
55
66
If you make changes to your `compose.yml` configuration, these changes are not reflected
77
after running this command. For example, changes to environment variables (which are added
@@ -11,7 +11,7 @@ long: |-
1111
If you are looking to configure a service's restart policy, please refer to
1212
[restart](https://github.com/compose-spec/compose-spec/blob/master/spec.md#restart)
1313
or [restart_policy](https://github.com/compose-spec/compose-spec/blob/master/deploy.md#restart_policy).
14-
usage: docker compose restart
14+
usage: docker compose restart [SERVICE...]
1515
pname: docker compose
1616
plink: docker_compose.yaml
1717
options:

0 commit comments

Comments
 (0)