DockerCLI/cmd/docker
Sebastiaan van Stijn 787caf2fe4
cmd/docker: fix completion for --context
registerCompletionFuncForGlobalFlags was called from newDockerCommand,
at which time no context-store is initialized yet, so it would return
a nil value, probably resulting in `store.Names` to panic, but these
errors are not shown when running the completion. As a result, the flag
completion would fall back to completing from filenames.

This patch changes the function to dynamically get the context-store;
this fixes the problem mentioned above, because at the time the completion
function is _invoked_, the CLI is fully initialized, and does have a
context-store available.

A (non-exported) interface is defined to allow the function to accept
alternative implementations (not requiring a full command.DockerCLI).

Before this patch:

    docker context create one
    docker context create two

    docker --context <TAB>
    .DS_Store                   .idea/                      Makefile
    .dockerignore               .mailmap                    build/
    ...

With this patch:

    docker context create one
    docker context create two

    docker --context <TAB>
    default  one      two

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 42b68a3ed7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-19 01:56:24 +02:00
..
internal/signals cli-plugins: terminate plugin when CLI exits 2023-12-12 13:54:30 +00:00
winresources Use goversioninfo to create Windows Version Info 2021-10-11 16:54:22 +02:00
aliases.go build: set default context builder if not specified 2022-11-04 08:42:34 +01:00
builder.go build: allow BuildKit to be used on Windows daemons that advertise it 2024-06-20 02:49:22 +02:00
builder_test.go Update go:build comments to go1.21 2024-06-18 12:17:13 +02:00
builder_windows_test.go build: set default context builder if not specified 2022-11-04 08:42:34 +01:00
completions.go cmd/docker: fix completion for --context 2024-07-19 01:56:24 +02:00
docker.go cmd/docker: fix completion for --context 2024-07-19 01:56:24 +02:00
docker_test.go refactor: remove test 2024-06-20 17:03:33 +02:00
docker_windows_386.go remove pre-go1.17 build-tags 2023-05-05 18:23:03 +02:00
docker_windows_amd64.go remove pre-go1.17 build-tags 2023-05-05 18:23:03 +02:00
docker_windows_arm.go remove pre-go1.17 build-tags 2023-05-05 18:23:03 +02:00
docker_windows_arm64.go remove pre-go1.17 build-tags 2023-05-05 18:23:03 +02:00