DockerCLI/cli/command/context
Sebastiaan van Stijn 9a493b1bf7
docker context rm: allow --force to ignore non-existing contexts
Before this change, running `docker context rm --force` would fail if the context
did not exist. This behavior was different from other commands, which allowed
ignoring non-existing objects.

For example; when trying to remove a non-existing volume, the command would
fail without "force":

```bash
docker volume rm nosuchvolume
Error: No such volume: nosuchvolume
echo $?
1
```

But using the `-f` / `--force` option would make the command complete successfully
(the error itself is still printed for informational purposes);

```bash
docker volume rm -f nosuchvolume
nosuchvolume
echo $?
0
```

With this patch, `docker context rm` behaves the same:

```bash
docker context rm nosuchcontext
context "nosuchcontext" does not exist
echo $?
1
```

```bash
docker context rm -f nosuchcontext
nosuchcontext
echo $?
0
```

This patch also simplifies how we check if the context exists; previously we
would try to read the context's metadata; this could fail if a context was
corrupted, or if an empty directory was present. This patch now only checks
if the directory exists, without first validating the context's data.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-29 10:57:51 +02:00
..
testdata introduce `context show` command 2022-04-25 14:40:24 +02:00
cmd.go introduce `context show` command 2022-04-25 14:40:24 +02:00
create.go cli/command/context: remove newContextMetadata() utility 2022-07-21 18:16:12 +02:00
create_test.go cli/command/context: remove deprecated io/ioutil and use t.TempDir() 2022-02-25 15:41:50 +01:00
export-import_test.go cli/command/context: remove deprecated io/ioutil and use t.TempDir() 2022-02-25 15:41:50 +01:00
export.go context export: remove docker context export --kubeconfig options 2022-02-24 12:26:09 +01:00
import.go Introduce .zip import for docker context 2019-05-29 12:58:45 -07:00
inspect.go introduce `context show` command 2022-04-25 14:40:24 +02:00
inspect_test.go cli/command/context: remove deprecated io/ioutil and use t.TempDir() 2022-02-25 15:41:50 +01:00
list.go Adopt Cobra completion v2 to support completion by CLI plugins 2022-05-12 12:59:10 +02:00
list_test.go cli/command/context: remove deprecated io/ioutil and use t.TempDir() 2022-02-25 15:41:50 +01:00
options.go Drop support for (archived) Compose-on-Kubernetes 2022-02-22 13:47:34 +01:00
remove.go docker context rm: allow --force to ignore non-existing contexts 2022-09-29 10:57:51 +02:00
remove_test.go docker context rm: allow --force to ignore non-existing contexts 2022-09-29 10:57:51 +02:00
show.go Adopt Cobra completion v2 to support completion by CLI plugins 2022-05-12 12:59:10 +02:00
show_test.go introduce `context show` command 2022-04-25 14:40:24 +02:00
update.go use our own version of text/tabwriter 2022-04-25 15:01:41 +02:00
update_test.go cli/command/context: remove deprecated io/ioutil and use t.TempDir() 2022-02-25 15:41:50 +01:00
use.go context use: don't create/update config file and directories if not needed 2022-07-29 14:20:05 +02:00
use_test.go context use: don't create/update config file and directories if not needed 2022-07-29 14:20:05 +02:00