-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
various improvements to shell completions #5238
Changes from all commits
eed0e5b
9207ff1
e3427f3
5e7bcbe
162d974
42b68a3
e4dd8b1
f30158d
7fe7223
d6f78cd
b1c0ddc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package container | ||
|
||
import ( | ||
"github.com/docker/cli/cli/command/completion" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/moby/sys/signal" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// allLinuxCapabilities is a list of all known Linux capabilities. | ||
// | ||
// This list was based on the containerd pkg/cap package; | ||
// https://github.com/containerd/containerd/blob/v1.7.19/pkg/cap/cap_linux.go#L133-L181 | ||
// | ||
// TODO(thaJeztah): add descriptions, and enable descriptions for our completion scripts (cobra.CompletionOptions.DisableDescriptions is currently set to "true") | ||
var allLinuxCapabilities = []string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like containerd/pkg/cap maintains a list of these: https://github.com/containerd/containerd/blob/78d3e205a51ec101f775a43bee6f4fdd8fc6b22b/pkg/cap/cap_linux.go#L133-L187 Perhaps we could help extracting this from (not a blocker for this PR though) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hehe, yes, look at the comment above; that's where I took the list from 😄. We could consider moving such things to a separate repo (or to be in a smaller module); one tricky bit there is that these are linux capabilities, so if we want to use them cross-platform (in our case, the CLI may be running on Windows), at least we'd have to make clear that they only apply to Linux, so we can't have that code be platform-specific at compile time ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, I didn't read the comment 🤦🏻 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we can't use it in the current form, but would be nice to avoid having to maintain this list by ourselves in future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah agreed. For this one I decided that it's not critical for the list to be up-to-date (even more accurate; completion may provide capabilities that are not supported by the daemon host if it's running an older kernel version), but for completion that should be mostly "OK"; the user doesn't have to use the completion, and can still type something else. For the So the most accurate thing to do would be to have API endpoints for these (i.e., let the daemon provide options that can be used) that are specifically crafted for purpose of completion (as lightweight as possible), but even if they're lightweight, there may still be some latency when connected to a remove machine, so that's something we should explore and consider pros/cons. |
||
"ALL", // magic value for "all capabilities" | ||
|
||
// caps35 is the caps of kernel 3.5 (37 entries) | ||
"CAP_CHOWN", // 2.2 | ||
"CAP_DAC_OVERRIDE", // 2.2 | ||
"CAP_DAC_READ_SEARCH", // 2.2 | ||
"CAP_FOWNER", // 2.2 | ||
"CAP_FSETID", // 2.2 | ||
"CAP_KILL", // 2.2 | ||
"CAP_SETGID", // 2.2 | ||
"CAP_SETUID", // 2.2 | ||
"CAP_SETPCAP", // 2.2 | ||
"CAP_LINUX_IMMUTABLE", // 2.2 | ||
"CAP_NET_BIND_SERVICE", // 2.2 | ||
"CAP_NET_BROADCAST", // 2.2 | ||
"CAP_NET_ADMIN", // 2.2 | ||
"CAP_NET_RAW", // 2.2 | ||
"CAP_IPC_LOCK", // 2.2 | ||
"CAP_IPC_OWNER", // 2.2 | ||
"CAP_SYS_MODULE", // 2.2 | ||
"CAP_SYS_RAWIO", // 2.2 | ||
"CAP_SYS_CHROOT", // 2.2 | ||
"CAP_SYS_PTRACE", // 2.2 | ||
"CAP_SYS_PACCT", // 2.2 | ||
"CAP_SYS_ADMIN", // 2.2 | ||
"CAP_SYS_BOOT", // 2.2 | ||
"CAP_SYS_NICE", // 2.2 | ||
"CAP_SYS_RESOURCE", // 2.2 | ||
"CAP_SYS_TIME", // 2.2 | ||
"CAP_SYS_TTY_CONFIG", // 2.2 | ||
"CAP_MKNOD", // 2.4 | ||
"CAP_LEASE", // 2.4 | ||
"CAP_AUDIT_WRITE", // 2.6.11 | ||
"CAP_AUDIT_CONTROL", // 2.6.11 | ||
"CAP_SETFCAP", // 2.6.24 | ||
"CAP_MAC_OVERRIDE", // 2.6.25 | ||
"CAP_MAC_ADMIN", // 2.6.25 | ||
"CAP_SYSLOG", // 2.6.37 | ||
"CAP_WAKE_ALARM", // 3.0 | ||
"CAP_BLOCK_SUSPEND", // 3.5 | ||
|
||
// caps316 is the caps of kernel 3.16 (38 entries) | ||
"CAP_AUDIT_READ", | ||
|
||
// caps58 is the caps of kernel 5.8 (40 entries) | ||
"CAP_PERFMON", | ||
"CAP_BPF", | ||
|
||
// caps59 is the caps of kernel 5.9 (41 entries) | ||
"CAP_CHECKPOINT_RESTORE", | ||
} | ||
|
||
// restartPolicies is a list of all valid restart-policies.. | ||
// | ||
// TODO(thaJeztah): add descriptions, and enable descriptions for our completion scripts (cobra.CompletionOptions.DisableDescriptions is currently set to "true") | ||
var restartPolicies = []string{ | ||
string(container.RestartPolicyDisabled), | ||
string(container.RestartPolicyAlways), | ||
string(container.RestartPolicyOnFailure), | ||
string(container.RestartPolicyUnlessStopped), | ||
} | ||
|
||
func completeLinuxCapabilityNames(cmd *cobra.Command, args []string, toComplete string) (names []string, _ cobra.ShellCompDirective) { | ||
return completion.FromList(allLinuxCapabilities...)(cmd, args, toComplete) | ||
} | ||
|
||
func completeRestartPolicies(cmd *cobra.Command, args []string, toComplete string) (names []string, _ cobra.ShellCompDirective) { | ||
return completion.FromList(restartPolicies...)(cmd, args, toComplete) | ||
} | ||
|
||
func completeSignals(cmd *cobra.Command, args []string, toComplete string) (names []string, _ cobra.ShellCompDirective) { | ||
// TODO(thaJeztah): do we want to provide the full list here, or a subset? | ||
signalNames := make([]string, 0, len(signal.SignalMap)) | ||
for k := range signal.SignalMap { | ||
signalNames = append(signalNames, k) | ||
} | ||
return completion.FromList(signalNames...)(cmd, args, toComplete) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check why we disable it here;
cli/cmd/docker/docker.go
Lines 92 to 96 in 9bb1a62
And here;
cli/cli-plugins/plugin/plugin.go
Lines 158 to 162 in 9bb1a62