Skip to content

Commit 23a8d38

Browse files
laurazardaustinvazquez
authored andcommitted
volume/update: require 1 argument/fix panic
This command was declaring that it requires at least 1 argument, when it needs exactly 1 argument. This was causing the CLI to panic when the command was invoked with no argument: `docker volume update` Signed-off-by: Laura Brehm <laurabrehm@hey.com> (cherry picked from commit daea277) Signed-off-by: Austin Vazquez <macedonv@amazon.com>
1 parent 3c827ab commit 23a8d38

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

cli/command/volume/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func newUpdateCommand(dockerCli command.Cli) *cobra.Command {
1818
cmd := &cobra.Command{
1919
Use: "update [OPTIONS] [VOLUME]",
2020
Short: "Update a volume (cluster volumes only)",
21-
Args: cli.RequiresMaxArgs(1),
21+
Args: cli.ExactArgs(1),
2222
RunE: func(cmd *cobra.Command, args []string) error {
2323
return runUpdate(cmd.Context(), dockerCli, args[0], availability, cmd.Flags())
2424
},

cli/command/volume/update_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package volume
2+
3+
import (
4+
"io"
5+
"testing"
6+
7+
"github.com/docker/cli/internal/test"
8+
"gotest.tools/v3/assert"
9+
)
10+
11+
func TestUpdateCmd(t *testing.T) {
12+
cmd := newUpdateCommand(
13+
test.NewFakeCli(&fakeClient{}),
14+
)
15+
cmd.SetArgs([]string{})
16+
cmd.SetOut(io.Discard)
17+
cmd.SetErr(io.Discard)
18+
19+
err := cmd.Execute()
20+
21+
assert.ErrorContains(t, err, "requires exactly 1 argument")
22+
}

0 commit comments

Comments
 (0)