Skip to content

Commit

Permalink
feat(ip): Complete neigh show and flush
Browse files Browse the repository at this point in the history
  • Loading branch information
yedayak authored and scop committed Apr 2, 2024
1 parent 216734b commit c7c3c03
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
28 changes: 27 additions & 1 deletion completions/ip
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ _comp_cmd_ip__link_types()
)"
}

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

_comp_cmd_ip()
{
local cur prev words cword comp_args
Expand Down Expand Up @@ -344,7 +357,20 @@ _comp_cmd_ip()
# TODO
;;
show | flush)
# TODO
case "$prev" in
nud)
_comp_cmd_ip__neigh_states "$1"
;;
dev)
_comp_compgen_available_interfaces
;;
nomaster | proxy | to | vrf) # TODO - Maybe we can complete vrf here?
:
;;
*)
_comp_compgen -- -W 'proxy to nud vrf dev nomaster'
;;
esac
;;
*)
((cword == subcword)) &&
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 @@ -23,6 +23,14 @@ def test_stats(self, completion):
# "link" was one of the first groups added, should always be there
assert "link" in completion

@pytest.mark.complete(
"ip neigh show nud ",
require_cmd=True,
skipif="ip neigh help 2>&1 | grep 'STATE :=' > /dev/null; (( $? != 0 ))",
)
def test_neigh_state(self, completion):
assert "stale" in completion

@pytest.mark.complete(
"ip monitor ",
require_cmd=True,
Expand Down

0 comments on commit c7c3c03

Please sign in to comment.