Commit Graph

1720 Commits

Author SHA1 Message Date
Sebastiaan van Stijn cfe6090d5d
cli/command/container: fix missing go:build tag
make shell
    make -C ./internal/gocompat/

    GO111MODULE=on go test -v
    # github.com/docker/cli/cli/command/container
    ../../cli/command/container/completion.go:37:28: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../cli/command/container/completion.go:82:25: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    ../../cli/command/container/completion.go:92:27: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    FAIL	gocompat [build failed]

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit d1d5353269)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-15 11:10:46 +01:00
Sebastiaan van Stijn 3df40364f6
update go:build tags to use go1.22
commit 4a7b04d412 configured golangci-lint
to use go1.23 semantics, which enabled the copyloopvar linter.

go1.22 now creates a copy of variables when assigned in a loop; make sure we
don't have files that may downgrade semantics to go1.21 in case that also means
disabling that feature; https://go.dev/ref/spec#Go_1.22

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 7c80e4f938)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-15 11:10:35 +01:00
Harald Albers 955e003345
Handle null completions with a default callback
Credits to thaJeztah

Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 06260e68f3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:55 +01:00
Harald Albers ce77f4a545
Add completion for `--volume-driver`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 4525fe37b4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:54 +01:00
Harald Albers e20bcf3565
Add completion for `--cgroupns`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit db0ed1e216)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:54 +01:00
Harald Albers 78544cd587
Add completion for `--uts`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 2915749279)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:54 +01:00
Harald Albers d11291966d
Add completion for --log-driver` and --log-opt`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 3a2503fa43)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:54 +01:00
Harald Albers 25ff89519f
Add completion for `--security-opt`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 9a9ae231a9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:54 +01:00
Harald Albers 83303411ee
Add completion for `--detach-keys`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 5f7c43e5e6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:53 +01:00
Harald Albers e25548d1c6
Add completion for `--userns`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 3292afe6e6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:53 +01:00
Harald Albers 99e60c4e39
Add completion for `--ulimit`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 5d709a8d9f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:53 +01:00
Harald Albers 6d087eb91b
Add completion for `--storage-opt`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 2d89339b34)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:53 +01:00
Harald Albers 83f79c3e86
Add completion for `--pid`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit ac7bde6f64)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:04:48 +01:00
Harald Albers 6f439ea4a4
Add completion for `--link`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit e513454244)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:00:47 +01:00
Harald Albers 7e35be13ea
Add completion for `--ipc`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit c555327f0b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:00:47 +01:00
Harald Albers f9ccc50304
Add completion for `--attach`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit b598ec8cdb)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:00:47 +01:00
Harald Albers 38e37778b0
Share the container completions
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 761d76750c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 17:00:47 +01:00
Harald Albers 8caf347188
Add tests for completions that call the API
Some small adjustments for this branch due to some times being renamed
in master;

    63.76 cli/command/system/cmd.go:1: : # github.com/docker/cli/cli/command/system [github.com/docker/cli/cli/command/system.test]
    63.76 cli/command/system/client_test.go:22:79: undefined: container.Summary
    63.76 cli/command/system/client_test.go:38:103: undefined: container.Summary
    63.76 cli/command/system/client_test.go:42:21: undefined: container.Summary
    63.76 cli/command/system/completion_test.go:30:86: undefined: container.Summary
    63.76 cli/command/system/completion_test.go:31:25: undefined: container.Summary
    63.76 cli/command/system/completion_test.go:42:86: undefined: container.Summary (typecheck)

Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit e1c5180dba)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 14:55:02 +01:00
Harald Albers 9e7d01bfb3
Add completion for `events --filter`
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit d4f4cf1418)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-14 14:53:54 +01:00
Sebastiaan van Stijn 168a4bdc05
cli/command: PromptUserForCredentials: suppress unhandled errors
Keep the linters (and my IDE) happy; these errors should be safe to ignore.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 4b7a1e4613)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:41 +01:00
Sebastiaan van Stijn ddeb7eb4ed
cli/command: PromptUserForCredentials: use consts for all hints
This message resulted in code-lines that were too long; move it to a
const together with the other hint. While at it, also suppress unhandled
error, and touch-up the code-comment.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 378a3d7d36)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:41 +01:00
Sebastiaan van Stijn da3a1c3027
cli/command: PromptUserForCredentials: print error on terminal restore fail
If restoring the terminal state fails, "echo" no longer works, which means
that anything the user types is no longer shown. The login itself may already
have succeeded, so we should not fail the command, but it's good to inform
the user that this happened, which may give them a clue why things no longer
work as they expect them to work.

With this patch:

    docker login -u yourname
    Password:
    Error: failed to restore terminal state to echo input: something bad happened

    Login Succeeded

We should consider printing instructions how  to restore this manually (other
than restarting the shell). e.g., 'run stty echo' when in a Linux or macOS shell,
but PowerShell and CMD.exe may need different instructions.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 3d8b49523d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:41 +01:00
Sebastiaan van Stijn 1377310110
cli/command: PromptUserForCredentials: always trim password
we don't support empty passwords; when prompting the user for a password,
we already trim the result, but we didn't do the same for a password that's
passed through stdin or through the `-p` / `--password` flag.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a21a5f4243)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:41 +01:00
Sebastiaan van Stijn 78dbcca264
cli/command: PromptUserForCredentials: move trimming where it's used
- move trimming defaultUsername inside the if-branch, as it's the only
  location where the result of the trimmed username is use.
- do the reverse for trimming argUser, because the result of trimming
  argUser is used outside of the if-branch (not just for the condition).
  putting it inside the condition makes it easy to assume the result is
  only used locally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit eda78e9cdc)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:41 +01:00
Sebastiaan van Stijn 97c25b7574
cli/command: PromptUserForCredentials: move "post" check for empty name
move the "post" check for username being empty inside the branch
that's handling the username, as it's the only branch where username
is mutated after checking if it's empty.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 581cf36bd4)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:41 +01:00
Sebastiaan van Stijn 05455f8505
cli/command: PromptUserForCredentials: inline isDefaultRegistry
remove isDefaultRegistry and inline it where it's used; the code-comment
already outlines what we're looking for, so the intermediate var didn't
add much currently.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a55cfe5f82)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:40 +01:00
Sebastiaan van Stijn d23ab524c3
cli/command: PromptUserForCredentials: remove named output variables
This function has multiple conditional branches, which makes it harder
to see at a glance whether authConfig may be partially populated. This
patch instead returns a fresh instance for error returns to prevent any
confusion.

It also removes the named output variables, as they're now no longer used,
and the returned types should already be descriptive enough to understand
what's returned.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 3a8485085d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-13 23:32:40 +01:00
Giedrius Jonikas 470ab05503
Buffer 'docker stats' text to avoid terminal flickering
This change reduces the flickering of the terminal when
running `docker stats` by buffering the formatted stats
text and printing it in one write.

Should also consume less CPU as we now only have to issue
a single syscall to write the stats text to the terminal.

Signed-off-by: Giedrius Jonikas <giedriusj1@gmail.com>
(cherry picked from commit 0b16070ae6)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-10-31 14:29:38 +01:00
Sebastiaan van Stijn 05c860e866
Merge pull request #5548 from thaJeztah/27.x_backport_plugin_better_error
[27.x backport] cli/command/plugins: use errors.Join instead of custom cli.Errors, and deprecate cli.Errors
2024-10-22 10:42:38 +02:00
Sebastiaan van Stijn df7e6e5c5f
cli/command/container: TestWaitExitOrRemoved use subtests
=== RUN   TestWaitExitOrRemoved
    === RUN   TestWaitExitOrRemoved/normal-container
    === RUN   TestWaitExitOrRemoved/give-me-exit-code-42
    === RUN   TestWaitExitOrRemoved/i-want-a-wait-error
    time="2024-10-13T18:48:14+02:00" level=error msg="Error waiting for container: removal failed"
    === RUN   TestWaitExitOrRemoved/non-existent-container-id
    time="2024-10-13T18:48:14+02:00" level=error msg="error waiting for container: no such container: non-existent-container-id"
    --- PASS: TestWaitExitOrRemoved (0.00s)
        --- PASS: TestWaitExitOrRemoved/normal-container (0.00s)
        --- PASS: TestWaitExitOrRemoved/give-me-exit-code-42 (0.00s)
        --- PASS: TestWaitExitOrRemoved/i-want-a-wait-error (0.00s)
        --- PASS: TestWaitExitOrRemoved/non-existent-container-id (0.00s)
    PASS

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 35d7b1a7a6)
Signed-off-by: Austin Vazquez <macedonv@amazon.com>
2024-10-21 15:53:20 +00:00
Sebastiaan van Stijn 254b966b0d
cli/command/container: set empty args in tests and discard output
Prevent some tests from failing when running from a pre-compiled
testbinary, and discard output to make the output less noisy.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 3b38dc67be)
Signed-off-by: Austin Vazquez <macedonv@amazon.com>
2024-10-21 15:53:09 +00:00
Sebastiaan van Stijn a8a8f68268
cli/command: ConfigureAuth: fix deprecation comment
Deprecation comments must have an empty line before them, otherwise tools
and linters may not recognise them. While fixing this, also updated the
reference to PromptUserForCredentials to be a docs-link to make it clickable.

Updates 6e4818e7d6.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 54e3685bcd)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-19 13:10:31 +02:00
Sebastiaan van Stijn d3bf82db86
cli/command/plugins: use errors.Join instead of custom cli.Errors
This command was using a custom "multi-error" implementation, but it
had some limitations, and the formatting wasn't great.

This patch replaces it with Go's errors.Join.

Before:

    docker plugin remove one two three
    Error response from daemon: plugin "one" not found, Error response from daemon: plugin "two" not found, Error response from daemon: plugin "three" not found

After:

    docker plugin remove one two three
    Error response from daemon: plugin "one" not found
    Error response from daemon: plugin "two" not found
    Error response from daemon: plugin "three" not found

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 71ebbb81ae)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-19 10:36:33 +02:00
Harald Albers b018e55ca4
Only complete removable containers if --force is not given
Signed-off-by: Harald Albers <github@albersweb.de>
(cherry picked from commit 147630a309)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:43:03 +02:00
Sebastiaan van Stijn e2831282ee
completion: add test for VolumeNames
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e1c472a436)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:43:03 +02:00
Sebastiaan van Stijn b68bf3afe4
completion: add test for NetworkNames
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 302d73f990)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:43:03 +02:00
Sebastiaan van Stijn 77d002ae25
completion: add test for ImageNames
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit ab418a38d8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:43:01 +02:00
Sebastiaan van Stijn 95e329d3e3
completion: add test for ContainerNames
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit f3b4094eb0)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:42:10 +02:00
Sebastiaan van Stijn 02da13fb18
completion: add test for NoComplete
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit be197da6b8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:11:05 +02:00
Sebastiaan van Stijn 62230c7ec2
completion: add test for FromList
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 51713196c9)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:11:05 +02:00
Sebastiaan van Stijn 954dba4482
completion: add test for FileNames
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a5ca5b33f1)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:11:05 +02:00
Sebastiaan van Stijn 7d1fa132fb
completion: add test for EnvVarNames
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 8f2e5662e7)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:11:05 +02:00
Sebastiaan van Stijn b6e7eba447
completion: ContainerNames: don't panic on nil filter
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit b8cddc63ad)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:11:04 +02:00
Sebastiaan van Stijn 099d4baeed
cli/command/image: add shell completion for --platform flags
With this patch, completion is provided for `--platform` flags:

    docker pull --platform<TAB>
    linux           linux/amd64     linux/arm/v5    linux/arm/v7    linux/arm64/v8  linux/riscv64   wasip1          windows
    linux/386       linux/arm       linux/arm/v6    linux/arm64     linux/ppc64le   linux/s390x     wasip1/wasm     windows/amd64

Note that `docker buildx build` (with BuildKit) does not yet provide completion;
it's provided through buildx, and uses a different format (accepting multiple
comma-separated platforms). Interestingly, tab-completion for `docker build`
currently uses completion for non-buildkit, and has some other issues that may
have to be looked into.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit d42cf96e15)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:10:59 +02:00
Sebastiaan van Stijn dd4b370d3c
cli/command/container: add shell completion for --platform flags
With this patch, completion is provided for `--platform` flags:

    docker run --platform<TAB>
    linux           linux/amd64     linux/arm/v5    linux/arm/v7    linux/arm64/v8  linux/riscv64   wasip1          windows
    linux/386       linux/arm       linux/arm/v6    linux/arm64     linux/ppc64le   linux/s390x     wasip1/wasm     windows/amd64

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 8c7f713db6)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:10:59 +02:00
Sebastiaan van Stijn 64e98fa375
cli/command/completion: add Platforms
Add a utility for completing platform strings.

Platforms offers completion for platform-strings. It provides a non-exhaustive
list of platforms to be used for completion. Platform-strings are based on
[runtime.GOOS] and [runtime.GOARCH], but with (optional) variants added. A
list of recognised os/arch combinations from the Go runtime can be obtained
through "go tool dist list".

Some noteworthy exclusions from this list:

  - arm64 images ("windows/arm64", "windows/arm64/v8") do not yet exist for windows.
  - we don't (yet) include `os-variant` for completion (as can be used for Windows images)
  - we don't (yet) include platforms for which we don't build binaries, such as
    BSD platforms (freebsd, netbsd, openbsd), android, macOS (darwin).
  - we currently exclude architectures that may have unofficial builds,
    but don't have wide adoption (and no support), such as loong64, mipsXXX,
    ppc64 (non-le) to prevent confusion.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit ce1aebcc30)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:10:58 +02:00
Sebastiaan van Stijn e6c6658563
cli/command/container: add unit tests for completion helpers
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit d49e72c0ac)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:08:29 +02:00
Sebastiaan van Stijn 52ac568385
cli/container: use github.com/moby/sys/capability for completions
We used a hard-coded list of capabilities that we copied from containerd,
but the new "capability" package allows use to have a maintained list
of capabilities.

There's likely still some improvements to be made;

First of all, the capability package could provide a function to get the list
of strings.

On the completion-side, we need to consider what format is most convenient;
currently we use the canonical name (uppercase and "CAP_" prefix), however,
tab-completion is case-sensitive by default, so requires the user to type
uppercase letters to filter the list of options.

Bash completion provides a `completion-ignore-case on` option to make completion
case-insensitive (https://askubuntu.com/a/87066), but it looks to be a global
option; the current cobra.CompletionOptions also don't provide this as an option
to be used in the generated completion-script.

Fish completion has `smartcase` (by default?) which matches any case if
all of the input is lowercase.

Zsh does not have a dedicated option, but allows setting matching-rules
(see https://superuser.com/a/1092328).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 462e08219d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-10-17 23:08:14 +02:00
Sebastiaan van Stijn cb3048fbeb
Merge pull request #5519 from thaJeztah/27.x_backport_no_underline
[27.x backport] Do not underline image name
2024-10-08 17:09:05 +02:00
Sebastiaan van Stijn 5721cdc76d
Merge pull request #5518 from thaJeztah/27.x_backport_change_to_inuse
[27.x backport] Images Tree: Change 'Used' to 'In Use'
2024-10-08 17:08:38 +02:00