Skip to content

container: Complete local paths for docker cp - #7521

Open
a3ylf wants to merge 1 commit into
docker:masterfrom
a3ylf:3040-cp-local-path-completion
Open

a3ylf wants to merge 1 commit into
docker:masterfrom
a3ylf:3040-cp-local-path-completion

Conversation

@a3ylf

@a3ylf a3ylf commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Related to: #3040 (local path completion)
Related to: #2789 (legacy Fish completion)

Summary

docker cp ./ and docker cp example:/tmp/file ./ disable file completion, so the shell cannot suggest local files or directories.

Register a Cobra completion handler that delegates local paths to the shell. Use the existing copy-argument parser to distinguish container paths from local paths, including paths containing colons. Suppress local file suggestions for container paths, container destinations after a local source, stdin/stdout, and extra arguments. Cover both docker cp and docker container cp through completion requests.

This addresses the local-path portion of #3040. Completing paths inside containers remains outside this change.

Validation on Linux:

  • The 18 local-path regression cases fail on the original command. All 34 completion cases pass with the fix, including under go test -race ./cli/command/container -run '^TestCopyCompletion$'.
  • All 64 packages with unit tests pass using Go 1.27.4 and the repository's non-E2E package selection.
  • Repository-pinned golangci-lint 2.14.0 reports zero issues for ./cli/command/container/... with Go 1.27.4. Command-reference generation succeeds.
  • Eight completion requests against the rebuilt CLI pass, covering both command forms, local and container paths, flags, and extra arguments.

The broader container-package race run fails in TestInitTtySizeErrors; the same race reproduces with the unmodified base source. No daemon-dependent E2E tests were run.

Release notes

Enable local file and directory completion for docker cp and docker container cp.

Delegate local source and destination path completion to the shell, while suppressing local suggestions for container paths and extra arguments. Cover both command forms through Cobra completion requests.

Related to: docker#3040

Signed-off-by: Alexandre Rodrigues <alexandre3ylf@gmail.com>
@a3ylf
a3ylf marked this pull request as ready for review November 14, 2026 00:36
@a3ylf
a3ylf requested review from a team and thaJeztah as code owners November 14, 2026 00:36
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants