Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[27.1 backport] assorted fixes and enhancements for shell-completion #5261

Merged
merged 14 commits into from
Jul 19, 2024

Conversation

thaJeztah
Copy link
Member

backport:

- Description for the changelog

- Enable shell completion for `docker image rm`, `docker image history`, and `docker image inspect`.
- Add and improve shell completions for various flags

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

fredden and others added 14 commits July 19, 2024 01:55
Signed-off-by: Dan Wallis <[email protected]>
(cherry picked from commit c7d46aa)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
It's not initialized, because there's no `docker` command installed
by default, but at least this makes sure that the basics are present
for testing.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 3d80b7b)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Add a "completion" target to install the generated completion
scripts inside the dev-container. As generating this script
depends on the docker binary, it calls "make binary" first.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 3f3ecb9)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
- explicitly suppress unhandled errors
- remove names for unused arguments

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit eed0e5b)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
This is just a convenience function to allow defining completion to
use the default (complete with filenames and directories).

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 9207ff1)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
EnvVarNames offers completion for environment-variable names. This
completion can be used for "--env" and "--build-arg" flags, which
allow obtaining the value of the given environment-variable if present
in the local environment, so we only should complete the names of the
environment variables, and not their value. This also prevents the
completion script from printing values of environment variables
containing sensitive values.

For example;

    export MY_VAR=hello
    docker run --rm --env MY_VAR alpine printenv MY_VAR
    hello

Before this patch:

    docker run --env GO
    GO111MODULE=auto        GOLANG_VERSION=1.21.12  GOPATH=/go              GOTOOLCHAIN=local

With this patch:

    docker run --env GO<tab>
    GO111MODULE     GOLANG_VERSION  GOPATH          GOTOOLCHAIN

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit e3427f3)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
It's an alias for cobra.FixedCompletions but takes a variadic list
of strings, so that it's not needed to construct an array for this.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 5e7bcbe)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
"docker run" and "docker create" are mostly identical, so we can copy
the same completion functions,

We could possibly create a utility for this (similar to `addFlags()` which
configures both commands with the flags they share). I considered combining
his with `addFlags()`, but that utility is also used in various tests, in
which we don't need this feature, so keeping that for a future exercise.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 162d974)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
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 <[email protected]>
(cherry picked from commit 42b68a3)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Before this, it would panic when a nil-interface was passed.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit e4dd8b1)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
With this patch:

    docker run --cap-add <TAB>
    ALL                     CAP_KILL                CAP_SETUID
    CAP_AUDIT_CONTROL       CAP_LEASE               CAP_SYSLOG
    CAP_AUDIT_READ          CAP_LINUX_IMMUTABLE     CAP_SYS_ADMIN
    CAP_AUDIT_WRITE         CAP_MAC_ADMIN           CAP_SYS_BOOT
    CAP_BLOCK_SUSPEND       CAP_MAC_OVERRIDE        CAP_SYS_CHROOT
    CAP_BPF                 CAP_MKNOD               CAP_SYS_MODULE
    CAP_CHECKPOINT_RESTORE  CAP_NET_ADMIN           CAP_SYS_NICE
    CAP_CHOWN               CAP_NET_BIND_SERVICE    CAP_SYS_PACCT
    CAP_DAC_OVERRIDE        CAP_NET_BROADCAST       CAP_SYS_PTRACE
    CAP_DAC_READ_SEARCH     CAP_NET_RAW             CAP_SYS_RAWIO
    CAP_FOWNER              CAP_PERFMON             CAP_SYS_RESOURCE
    CAP_FSETID              CAP_SETFCAP             CAP_SYS_TIME
    CAP_IPC_LOCK            CAP_SETGID              CAP_SYS_TTY_CONFIG
    CAP_IPC_OWNER           CAP_SETPCAP             CAP_WAKE_ALARM

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit f30158d)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
With this patch:

    docker run --restart <TAB>
    always  no  on-failure  unless-stopped

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit 7fe7223)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
With this patch:

    docker run --volumes-from amazing_nobel
    amazing_cannon     boring_wozniak         determined_banzai
    elegant_solomon    reverent_booth         amazing_nobel

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit d6f78cd)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
With this patch:

    docker run --stop-signal <TAB>
    ABRT  IOT      RTMAX-4   RTMIN     RTMIN+11  TSTP
    ALRM  KILL     RTMAX-5   RTMIN+1   RTMIN+12  TTIN
    BUS   PIPE     RTMAX-6   RTMIN+2   RTMIN+13  TTOU
    CHLD  POLL     RTMAX-7   RTMIN+3   RTMIN+14  URG
    CLD   PROF     RTMAX-8   RTMIN+4   RTMIN+15  USR1
    CONT  PWR      RTMAX-9   RTMIN+5   SEGV      USR2
    FPE   QUIT     RTMAX-10  RTMIN+6   STKFLT    VTALRM
    HUP   RTMAX    RTMAX-11  RTMIN+7   STOP      WINCH
    ILL   RTMAX-1  RTMAX-12  RTMIN+8   SYS       XCPU
    INT   RTMAX-2  RTMAX-13  RTMIN+9   TERM      XFSZ
    IO    RTMAX-3  RTMAX-14  RTMIN+10  TRAP

Signed-off-by: Sebastiaan van Stijn <[email protected]>
(cherry picked from commit b1c0ddc)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 58.13953% with 18 lines in your changes missing coverage. Please review.

Project coverage is 61.46%. Comparing base (69a2c9f) to head (66ec714).
Report is 12 commits behind head on 27.0.

Additional details and impacted files
@@            Coverage Diff             @@
##             27.0    #5261      +/-   ##
==========================================
+ Coverage   61.37%   61.46%   +0.08%     
==========================================
  Files         295      299       +4     
  Lines       20811    20823      +12     
==========================================
+ Hits        12773    12798      +25     
+ Misses       7119     7114       -5     
+ Partials      919      911       -8     

@thaJeztah thaJeztah merged commit 33bf62c into docker:27.0 Jul 19, 2024
107 checks passed
@thaJeztah thaJeztah deleted the 27.1_backport_completion_enhancements branch July 19, 2024 10:05
@thaJeztah thaJeztah changed the title [27.0 backport] assorted fixes and enhancements for shell-completion [27.1 backport] assorted fixes and enhancements for shell-completion Jul 19, 2024
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.

4 participants