Merge pull request #27132 from NotSoFancyName/interface-completion

cmd: add autocomplete for network create --interface-name flag
This commit is contained in:
openshift-merge-bot[bot]
2025-09-30 12:28:50 +00:00
committed by GitHub
3 changed files with 24 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io/fs"
"net"
"os"
"path"
"path/filepath"
@ -1880,6 +1881,20 @@ func AutocompleteNetworkFilters(cmd *cobra.Command, args []string, toComplete st
return completeKeyValues(toComplete, kv)
}
// AutocompleteNetworkInterfaceNames - Autocomplete network create --interface-name options.
func AutocompleteNetworkInterfaceNames(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
interfaces, err := net.Interfaces()
if err != nil {
cobra.CompErrorln(err.Error())
return nil, cobra.ShellCompDirectiveDefault
}
interfaceNames := make([]string, 0, len(interfaces))
for _, iface := range interfaces {
interfaceNames = append(interfaceNames, iface.Name)
}
return interfaceNames, cobra.ShellCompDirectiveNoFileComp
}
// AutocompleteVolumeFilters - Autocomplete volume ls --filter options.
func AutocompleteVolumeFilters(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
local := func(_ string) ([]string, cobra.ShellCompDirective) {

View File

@ -85,7 +85,7 @@ func networkCreateFlags(cmd *cobra.Command) {
interfaceFlagName := "interface-name"
flags.StringVar(&networkCreateOptions.InterfaceName, interfaceFlagName, "", "interface name which is used by the driver")
_ = cmd.RegisterFlagCompletionFunc(interfaceFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(interfaceFlagName, common.AutocompleteNetworkInterfaceNames)
flags.BoolVar(&networkCreateOptions.DisableDNS, "disable-dns", false, "disable dns plugin")

View File

@ -422,3 +422,11 @@ function _check_no_suggestions() {
_check_completion_end NoFileComp
}
@test "podman network create --interface-name" {
run_completion network create --interface-name l
assert "$output" =~ '.*lo.*' "Loopback interface should be present by default"
_check_completion_end NoFileComp
}