mirror of
https://github.com/containers/podman.git
synced 2025-10-16 10:43:52 +08:00
Merge pull request #27122 from nothiaki/feat-sysctl-completion
feat(completions): sysctl completion
This commit is contained in:
@ -1954,3 +1954,35 @@ func AutocompleteSSH(cmd *cobra.Command, args []string, toComplete string) ([]st
|
|||||||
func AutocompleteHealthOnFailure(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteHealthOnFailure(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
return define.SupportedHealthCheckOnFailureActions, cobra.ShellCompDirectiveNoFileComp
|
return define.SupportedHealthCheckOnFailureActions, cobra.ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutocompleteSysctl - autocomplete list all sysctl names
|
||||||
|
func AutocompleteSysctl(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
var completions []string
|
||||||
|
sysPath := "/proc/sys"
|
||||||
|
|
||||||
|
err := filepath.Walk(sysPath, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() {
|
||||||
|
rel, err := filepath.Rel(sysPath, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sysctlName := strings.ReplaceAll(rel, string(os.PathSeparator), ".")
|
||||||
|
|
||||||
|
if strings.HasPrefix(sysctlName, toComplete) {
|
||||||
|
completions = append(completions, sysctlName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, cobra.ShellCompDirectiveError
|
||||||
|
}
|
||||||
|
|
||||||
|
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
@ -733,8 +733,8 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
|
|||||||
sysctlFlagName, []string{},
|
sysctlFlagName, []string{},
|
||||||
"Sysctl options",
|
"Sysctl options",
|
||||||
)
|
)
|
||||||
//TODO: Add function for sysctl completion.
|
|
||||||
_ = cmd.RegisterFlagCompletionFunc(sysctlFlagName, completion.AutocompleteNone)
|
_ = cmd.RegisterFlagCompletionFunc(sysctlFlagName, AutocompleteSysctl)
|
||||||
|
|
||||||
securityOptFlagName := "security-opt"
|
securityOptFlagName := "security-opt"
|
||||||
createFlags.StringArrayVar(
|
createFlags.StringArrayVar(
|
||||||
|
@ -410,3 +410,15 @@ function _check_no_suggestions() {
|
|||||||
# cleanup container
|
# cleanup container
|
||||||
run_podman rm $ctrname
|
run_podman rm $ctrname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# bats test_tags=ci:parallel
|
||||||
|
@test "podman run --sysctl completion for sysctl" {
|
||||||
|
skip_if_remote "sysctl option not working via remote"
|
||||||
|
|
||||||
|
run_completion run --sysctl net.
|
||||||
|
|
||||||
|
assert "$output" =~ "^net\." \
|
||||||
|
"Only suggestions with 'net.' should be present for podman run --sysctl net."
|
||||||
|
|
||||||
|
_check_completion_end NoFileComp
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user