Skip to content

Commit

Permalink
Merge pull request scop#1130 from yedayak/ip-link-types
Browse files Browse the repository at this point in the history
Complete ip link types
  • Loading branch information
scop committed Mar 13, 2024
2 parents c8920c5 + f3a9be3 commit 4f9ad00
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
36 changes: 22 additions & 14 deletions completions/ip
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ _comp_cmd_ip__netns()
)"
}

_comp_cmd_ip__link_types()
{
_comp_compgen_split -- "$(
{
${1-ip} -c=never link help || ${1-ip} link help
} 2>&1 | command sed -e \
'/TYPE := /,/}/!d' -e \
's/.*{//' -e \
's/}.*//' -e \
's/|/ /g'
)"
}

_comp_cmd_ip()
{
local cur prev words cword comp_args
Expand Down Expand Up @@ -87,19 +100,12 @@ _comp_cmd_ip()
# TODO
;;
delete)
case $((cword - subcword)) in
1)
_comp_compgen_available_interfaces
;;
2)
_comp_compgen -- -W 'type'
;;
3)
[[ $prev == type ]] &&
_comp_compgen -- -W 'vlan veth vcan dummy ifb
macvlan can'
;;
esac
if [[ $prev == type ]]; then
_comp_cmd_ip__link_types "$1"
else
_comp_compgen_available_interfaces
_comp_compgen -a -- -W 'type'
fi
;;
set)
if ((cword - subcword == 1)); then
Expand Down Expand Up @@ -164,11 +170,13 @@ _comp_cmd_ip()
_comp_compgen_available_interfaces
_comp_compgen -a -- -W 'dev scope to label dynamic
permanent tentative deprecated dadfailed temporary
primary secondary up'
primary secondary up type'
elif [[ $prev == dev ]]; then
_comp_compgen_available_interfaces
elif [[ $prev == scope ]]; then
_comp_cmd_ip__iproute2_etc rt_scopes
elif [[ $prev == type ]]; then
_comp_cmd_ip__link_types "$1"
fi
;;
*)
Expand Down
8 changes: 8 additions & 0 deletions test/t/test_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def test_monitor(self, completion):
def test_netconf(self, completion):
assert "show" in completion

@pytest.mark.complete(
"ip addr show type ",
require_cmd=True,
skipif="ip link help 2>/dev/null; (( $? != 255 ))",
)
def test_addr_type(self, completion):
assert "bridge" in completion

@pytest.mark.complete("ip -", require_cmd=True)
def test_options(self, completion):
assert "-family" in completion

0 comments on commit 4f9ad00

Please sign in to comment.