From 5d709a8d9f54fc893ea1cbd4ec71c4cb6f7f3e1e Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Thu, 24 Oct 2024 14:04:15 +0000 Subject: [PATCH] Add completion for `--ulimit` Signed-off-by: Harald Albers --- cli/command/container/completion.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cli/command/container/completion.go b/cli/command/container/completion.go index cde6411a42..beb8febea8 100644 --- a/cli/command/container/completion.go +++ b/cli/command/container/completion.go @@ -70,6 +70,7 @@ func addCompletions(cmd *cobra.Command, dockerCLI completion.APIClientProvider) _ = cmd.RegisterFlagCompletionFunc("restart", completeRestartPolicies) _ = cmd.RegisterFlagCompletionFunc("stop-signal", completeSignals) _ = cmd.RegisterFlagCompletionFunc("storage-opt", completeStorageOpt) + _ = cmd.RegisterFlagCompletionFunc("ulimit", completeUlimit) _ = cmd.RegisterFlagCompletionFunc("volumes-from", completion.ContainerNames(dockerCLI, true)) } @@ -120,6 +121,32 @@ func completeStorageOpt(_ *cobra.Command, _ []string, _ string) ([]string, cobra return []string{"size="}, cobra.ShellCompDirectiveNoSpace } +// completeUlimit implements shell completion for the `--ulimit` option of `run` and `create`. +func completeUlimit(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + limits := []string{ + "as", + "chroot", + "core", + "cpu", + "data", + "fsize", + "locks", + "maxlogins", + "maxsyslogins", + "memlock", + "msgqueue", + "nice", + "nofile", + "nproc", + "priority", + "rss", + "rtprio", + "sigpending", + "stack", + } + return postfixWith("=", limits), cobra.ShellCompDirectiveNoSpace +} + // containerNames contacts the API to get names and optionally IDs of containers. // In case of an error, an empty list is returned. func containerNames(dockerCLI completion.APIClientProvider, cmd *cobra.Command, args []string, toComplete string) []string {