DockerCLI/cli/command
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
..
builder Adopt Cobra completion v2 to support completion by CLI plugins 2022-05-12 12:59:10 +02:00
checkpoint completion v2: some small follow-ups 2022-05-12 13:25:15 +02:00
commands remove exec, push, pull, ps, images, info from "legacy" commands 2022-04-08 16:55:39 +02:00
completion Adopt Cobra completion v2 to support completion by CLI plugins 2022-05-12 12:59:10 +02:00
config linting: ST1005: error strings should not be capitalized (stylecheck) 2022-09-03 21:25:42 +02:00
container Merge pull request #3764 from thaJeztah/cli_remove_intermediate_var 2022-09-08 16:14:20 +02:00
context docker context rm: allow --force to ignore non-existing contexts 2022-09-29 10:57:51 +02:00
formatter linting: tabwriter: ignore stylecheck 2022-09-03 21:25:39 +02:00
idresolver bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-23 00:28:55 +01:00
image replace uses of deprecated env.Patch() 2022-09-22 17:28:07 +02:00
inspect linting: fix incorrectly formatted errors (revive) 2022-03-28 10:37:25 +02:00
manifest linting: ST1019: package is being imported more than once (stylecheck) 2022-09-03 21:25:36 +02:00
network format (GoDoc) comments with Go 1.19 to prepare for go updates 2022-07-19 19:10:16 +02:00
node linting: ST1005: error strings should not be capitalized (stylecheck) 2022-09-03 21:25:42 +02:00
plugin completion v2: some small follow-ups 2022-05-12 13:25:15 +02:00
registry format (GoDoc) comments with Go 1.19 to prepare for go updates 2022-07-19 19:10:16 +02:00
secret linting: ST1005: error strings should not be capitalized (stylecheck) 2022-09-03 21:25:42 +02:00
service linting: remove unused nolint comments (nolintlint) 2022-09-03 21:25:34 +02:00
stack linting: ST1019: package is being imported more than once (stylecheck) 2022-09-03 21:25:36 +02:00
swarm linting: ST1005: error strings should not be capitalized (stylecheck) 2022-09-03 21:25:42 +02:00
system Merge pull request #3656 from thaJeztah/fix_info_empty_labels 2022-07-19 21:09:25 +02:00
task linting: fix incorrectly formatted errors (revive) 2022-03-28 10:37:25 +02:00
testdata Dynamically register kubernetes context store endpoint type. 2019-05-20 13:28:11 +01:00
trust linting: ST1005: error strings should not be capitalized (stylecheck) 2022-09-03 21:25:42 +02:00
volume Deflake TestVolumeCreateClusterOpts 2022-06-03 11:52:51 +02:00
cli.go cli/command: NewDockerCli(): use WithStandardStreams() 2022-08-31 17:10:53 +02:00
cli_options.go cli/command: remove WithContextEndpointType() as it's unused 2022-07-21 18:11:50 +02:00
cli_options_test.go linting: os.Setenv() can be replaced by `t.Setenv()` (tenv) 2022-09-03 21:25:37 +02:00
cli_test.go replace uses of deprecated env.Patch() 2022-09-22 17:28:07 +02:00
context.go remove obsolete mutli-orchestrator support 2022-02-22 15:28:12 +01:00
context_test.go remove obsolete mutli-orchestrator support 2022-02-22 15:28:12 +01:00
defaultcontextstore.go cli/command: remove unused args from ResolveDefaultContext() 2022-07-21 18:11:48 +02:00
defaultcontextstore_test.go replace uses of deprecated env.Patch() 2022-09-22 17:28:07 +02:00
events_utils.go updated vendoring 2017-09-01 19:41:06 -04:00
registry.go registry: don't call "/info" API endpoint to get default registry 2022-03-15 16:30:42 +01:00
registry_test.go registry: don't call "/info" API endpoint to get default registry 2022-03-15 16:30:42 +01:00
streams.go Extract streams helpers from command package to their own package to remove a cyclic dependency from command to internal/containerizedengine 2019-01-28 14:36:00 +01:00
trust.go Refactor content_trust cli/flags handling 2018-03-08 15:00:43 -05:00
utils.go replace pkg/system Sequential funcs with moby/sys/sequential 2022-08-29 13:27:26 +02:00
utils_test.go cli/command: remove deprecated io/ioutil and use t.TempDir() 2022-02-25 15:42:14 +01:00