Skip to content

shell completions: add shell completion for docker rm --link and exclude legacy links for container names#6872

Open
thaJeztah wants to merge 2 commits intodocker:masterfrom
thaJeztah:link_completions
Open

shell completions: add shell completion for docker rm --link and exclude legacy links for container names#6872
thaJeztah wants to merge 2 commits intodocker:masterfrom
thaJeztah:link_completions

Conversation

@thaJeztah
Copy link
Member

cli/command/completion: ContainerNames: skip legacy link names

Inline StripNamePrefix and skip legacy links for completion.
Legacy links can be removed from a container, but only when
using docker [container] rm --link <link-name>.

When linking containers through legacy links, a container can get multiple
names; its own name, and a name for each link it's providing:

# create two containers with links between them

docker run -d --name one nginx:alpine
docker run -d --name two --link one:link1 --link one:link2 --link one:link3 nginx:alpine

# container "one" now has multiple names
docker ps --no-trunc --format '{{.Names}}'
two
one,two/link1,two/link2,two/link3

# running `docker rm --link` with a link-name removes a link:

docker rm --link two/link3
docker ps --no-trunc --format '{{.Names}}'
two
one,two/link1,two/link2

# but without `--link`, it resolves the linked container and removes it:
docker rm -fv two/link2
two/link2
docker ps --no-trunc --format '{{.Names}}'
two

Legacy links are deprecated, and this can be confusing, so let's not provide
completion for secondary names.

cli/command/container: add shell completion for docker rm --link

When linking containers through legacy links, a container can get multiple
names; its own name, and a name for each link it's providing:

# create two containers with links between them
docker run -d --name one nginx:alpine
docker run -d --name two --link one:link1 --link one:link2 --link one:link3 nginx:alpine

docker rm --link <tab>
two/link1 two/link2 two/link3

- How to verify it

- Human readable description for the release notes

shell completions: add shell completion for `docker rm --link` and exclude legacy links for container names

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/command/container/rm.go 12.50% 6 Missing and 1 partial ⚠️
cli/command/container/completion.go 86.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Inline StripNamePrefix and skip legacy links for completion.
Legacy links can be removed from a container, but only when
using `docker [container] rm --link <link-name>`.

When linking containers through legacy links, a container can get multiple
names; its own name, and a name for each link it's providing:

    # create two containers with links between them

    docker run -d --name one nginx:alpine
    docker run -d --name two --link one:link1 --link one:link2 --link one:link3 nginx:alpine

    # container "one" now has multiple names
    docker ps --no-trunc --format '{{.Names}}'
    two
    one,two/link1,two/link2,two/link3

    # running `docker rm --link` with a link-name removes a link:

    docker rm --link two/link3
    docker ps --no-trunc --format '{{.Names}}'
    two
    one,two/link1,two/link2

    # but without `--link`, it resolves the linked container and removes it:
    docker rm -fv two/link2
    two/link2
    docker ps --no-trunc --format '{{.Names}}'
    two

Legacy links are deprecated, and this can be confusing, so let's not provide
completion for secondary names.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
When linking containers through legacy links, a container can get multiple
names; its own name, and a name for each link it's providing:

    # create two containers with links between them
    docker run -d --name one nginx:alpine
    docker run -d --name two --link one:link1 --link one:link2 --link one:link3 nginx:alpine

    docker rm --link <tab>
    two/link1 two/link2 two/link3

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants