Use constants in completion of `--cgroupns`

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2024-10-30 15:55:19 +00:00
parent 5624d2cbfd
commit 8362a23b67
1 changed files with 5 additions and 1 deletions

View File

@ -115,7 +115,7 @@ func addCompletions(cmd *cobra.Command, dockerCLI completion.APIClientProvider)
_ = cmd.RegisterFlagCompletionFunc("cap-add", completeLinuxCapabilityNames)
_ = cmd.RegisterFlagCompletionFunc("cap-drop", completeLinuxCapabilityNames)
_ = cmd.RegisterFlagCompletionFunc("cgroup-parent", completion.NoComplete)
_ = cmd.RegisterFlagCompletionFunc("cgroupns", completion.FromList("host", "private"))
_ = cmd.RegisterFlagCompletionFunc("cgroupns", completeCgroupns())
_ = cmd.RegisterFlagCompletionFunc("cpu-period", completion.NoComplete)
_ = cmd.RegisterFlagCompletionFunc("cpu-quota", completion.NoComplete)
_ = cmd.RegisterFlagCompletionFunc("cpu-rt-period", completion.NoComplete)
@ -188,6 +188,10 @@ func addCompletions(cmd *cobra.Command, dockerCLI completion.APIClientProvider)
_ = cmd.RegisterFlagCompletionFunc("workdir", completion.NoComplete)
}
func completeCgroupns() completion.ValidArgsFn {
return completion.FromList(string(container.CgroupnsModeHost), string(container.CgroupnsModePrivate))
}
// completeDetachKeys implements shell completion for the `--detach-keys` option of `run` and `create`.
func completeDetachKeys(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return []string{"ctrl-"}, cobra.ShellCompDirectiveNoSpace