mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +08:00
Merge pull request #8699 from Luap99/network-flag-completion
shell completion for the network flag
This commit is contained in:
@ -313,6 +313,10 @@ func completeKeyValues(toComplete string, k keyValueCompletion) ([]string, cobra
|
|||||||
return suggestions, directive
|
return suggestions, directive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBoolCompletion(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
/* Autocomplete Functions for cobra ValidArgsFunction */
|
/* Autocomplete Functions for cobra ValidArgsFunction */
|
||||||
|
|
||||||
// AutocompleteContainers - Autocomplete all container names.
|
// AutocompleteContainers - Autocomplete all container names.
|
||||||
@ -797,6 +801,39 @@ func AutocompleteVolumeFlag(cmd *cobra.Command, args []string, toComplete string
|
|||||||
return volumes, directive
|
return volumes, directive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutocompleteNetworkFlag - Autocomplete network flag options.
|
||||||
|
func AutocompleteNetworkFlag(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
kv := keyValueCompletion{
|
||||||
|
"container:": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) },
|
||||||
|
"ns:": func(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return nil, cobra.ShellCompDirectiveDefault
|
||||||
|
},
|
||||||
|
"bridge": nil,
|
||||||
|
"none": nil,
|
||||||
|
"host": nil,
|
||||||
|
"private": nil,
|
||||||
|
"slirp4netns:": func(s string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
skv := keyValueCompletion{
|
||||||
|
"allow_host_loopback=": getBoolCompletion,
|
||||||
|
"cidr=": nil,
|
||||||
|
"enable_ipv6=": getBoolCompletion,
|
||||||
|
"outbound_addr=": nil,
|
||||||
|
"outbound_addr6=": nil,
|
||||||
|
"port_handler=": func(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return []string{"rootlesskit", "slirp4netns"}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return completeKeyValues(s, skv)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
networks, _ := getNetworks(cmd, toComplete)
|
||||||
|
suggestions, dir := completeKeyValues(toComplete, kv)
|
||||||
|
// add slirp4netns here it does not work correct if we add it to the kv map
|
||||||
|
suggestions = append(suggestions, "slirp4netns")
|
||||||
|
return append(networks, suggestions...), dir
|
||||||
|
}
|
||||||
|
|
||||||
// AutocompleteJSONFormat - Autocomplete format flag option.
|
// AutocompleteJSONFormat - Autocomplete format flag option.
|
||||||
// -> "json"
|
// -> "json"
|
||||||
func AutocompleteJSONFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteJSONFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
@ -974,17 +1011,14 @@ func AutocompletePodPsFilters(cmd *cobra.Command, args []string, toComplete stri
|
|||||||
|
|
||||||
// AutocompleteImageFilters - Autocomplete image ls --filter options.
|
// AutocompleteImageFilters - Autocomplete image ls --filter options.
|
||||||
func AutocompleteImageFilters(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteImageFilters(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
getBool := func(_ string) ([]string, cobra.ShellCompDirective) {
|
|
||||||
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
|
|
||||||
}
|
|
||||||
getImg := func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) }
|
getImg := func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) }
|
||||||
kv := keyValueCompletion{
|
kv := keyValueCompletion{
|
||||||
"before=": getImg,
|
"before=": getImg,
|
||||||
"since=": getImg,
|
"since=": getImg,
|
||||||
"label=": nil,
|
"label=": nil,
|
||||||
"reference=": nil,
|
"reference=": nil,
|
||||||
"dangling=": getBool,
|
"dangling=": getBoolCompletion,
|
||||||
"readonly=": getBool,
|
"readonly=": getBoolCompletion,
|
||||||
}
|
}
|
||||||
return completeKeyValues(toComplete, kv)
|
return completeKeyValues(toComplete, kv)
|
||||||
}
|
}
|
||||||
@ -1009,9 +1043,7 @@ func AutocompleteVolumeFilters(cmd *cobra.Command, args []string, toComplete str
|
|||||||
"scope=": local,
|
"scope=": local,
|
||||||
"label=": nil,
|
"label=": nil,
|
||||||
"opt=": nil,
|
"opt=": nil,
|
||||||
"dangling=": func(_ string) ([]string, cobra.ShellCompDirective) {
|
"dangling=": getBoolCompletion,
|
||||||
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
return completeKeyValues(toComplete, kv)
|
return completeKeyValues(toComplete, kv)
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func DefineNetFlags(cmd *cobra.Command) {
|
|||||||
networkFlagName, containerConfig.NetNS(),
|
networkFlagName, containerConfig.NetNS(),
|
||||||
"Connect a container to a network",
|
"Connect a container to a network",
|
||||||
)
|
)
|
||||||
_ = cmd.RegisterFlagCompletionFunc(networkFlagName, AutocompleteNetworks)
|
_ = cmd.RegisterFlagCompletionFunc(networkFlagName, AutocompleteNetworkFlag)
|
||||||
|
|
||||||
networkAliasFlagName := "network-alias"
|
networkAliasFlagName := "network-alias"
|
||||||
netFlags.StringSlice(
|
netFlags.StringSlice(
|
||||||
|
@ -61,7 +61,7 @@ func init() {
|
|||||||
|
|
||||||
networkFlagName := "network"
|
networkFlagName := "network"
|
||||||
flags.StringVar(&kubeOptions.Network, networkFlagName, "", "Connect pod to CNI network(s)")
|
flags.StringVar(&kubeOptions.Network, networkFlagName, "", "Connect pod to CNI network(s)")
|
||||||
_ = kubeCmd.RegisterFlagCompletionFunc(networkFlagName, common.AutocompleteNetworks)
|
_ = kubeCmd.RegisterFlagCompletionFunc(networkFlagName, common.AutocompleteNetworkFlag)
|
||||||
|
|
||||||
logDriverFlagName := "log-driver"
|
logDriverFlagName := "log-driver"
|
||||||
flags.StringVar(&kubeOptions.LogDriver, logDriverFlagName, "", "Logging driver for the container")
|
flags.StringVar(&kubeOptions.LogDriver, logDriverFlagName, "", "Logging driver for the container")
|
||||||
|
Reference in New Issue
Block a user