[27.1 backport] assorted fixes and enhancements for shell-completion#5261
Merged
thaJeztah merged 14 commits intodocker:27.0from Jul 19, 2024
Merged
Conversation
Signed-off-by: Dan Wallis <dan@wallis.nz> (cherry picked from commit c7d46aa) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl> (cherry picked from commit 3d80b7b) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl> (cherry picked from commit 3f3ecb9) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- explicitly suppress unhandled errors - remove names for unused arguments Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit eed0e5b) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl> (cherry picked from commit 9207ff1) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl>
(cherry picked from commit e3427f3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl> (cherry picked from commit 5e7bcbe) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
"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 <github@gone.nl> (cherry picked from commit 162d974) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 42b68a3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Before this, it would panic when a nil-interface was passed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit e4dd8b1) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl>
(cherry picked from commit f30158d)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
With this patch:
docker run --restart <TAB>
always no on-failure unless-stopped
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 7fe7223)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl>
(cherry picked from commit d6f78cd)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
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 <github@gone.nl>
(cherry picked from commit b1c0ddc)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
vvoland
approved these changes
Jul 19, 2024
Codecov ReportAttention: Patch coverage is
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
backport:
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)