Skip to content

Commit cd73e8c

Browse files
yedayakscop
authored andcommitted
feat(ip): Complete stats subcommand
1 parent 4f9ad00 commit cd73e8c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

completions/ip

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,41 @@ _comp_cmd_ip()
282282
;;
283283
esac
284284
;;
285+
stats)
286+
case "$subcmd" in
287+
show)
288+
if [[ $prev == dev ]]; then
289+
_comp_compgen_available_interfaces
290+
elif [[ $prev == group ]]; then
291+
_comp_compgen -- -W "$(
292+
# stats command was added after color, should always have it
293+
"$1" -c=never stats help 2>&1 |
294+
command sed -e \
295+
'/^GROUP := /,/}/!d' -e \
296+
's/^GROUP := //g' -e \
297+
'/:=/d' -e \
298+
's/[{}|]//g'
299+
)"
300+
elif [[ $prev == subgroup || $prev == suite ]]; then
301+
: # TODO: complete subgroup and suite
302+
else
303+
_comp_compgen -- -W 'dev group subgroup suite'
304+
fi
305+
;;
306+
set)
307+
if [[ $prev == dev ]]; then
308+
_comp_compgen_available_interfaces
309+
elif [[ $prev == l3_stats ]]; then
310+
_comp_compgen -- -W 'on off'
311+
else
312+
_comp_compgen -- -W 'dev l3_stats'
313+
fi
314+
;;
315+
*)
316+
_comp_compgen -- -W 'show set help'
317+
;;
318+
esac
319+
;;
285320

286321
n | neigh | neighbor | neighbour)
287322
case $subcmd in

test/t/test_ip.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ def test_2(self, completion):
1414
def test_r_r(self, completion):
1515
assert completion
1616

17+
@pytest.mark.complete(
18+
"ip stats show group ",
19+
require_cmd=True,
20+
skipif="ip stats help 2>/dev/null; (( $? != 255 ))",
21+
)
22+
def test_stats(self, completion):
23+
# "link" was one of the first groups added, should always be there
24+
assert "link" in completion
25+
1726
@pytest.mark.complete(
1827
"ip monitor ",
1928
require_cmd=True,

0 commit comments

Comments
 (0)