Skip to content

Commit e9eb03c

Browse files
Low-powerakinomyoga
authored andcommitted
feat(mfiutil): add new completion
1 parent 231a39d commit e9eb03c

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

completions/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ bashcomp_DATA = 2to3 \
261261
_mdbook \
262262
mdtool \
263263
medusa \
264+
mfiutil \
264265
mii-diag \
265266
mii-tool \
266267
minicom \

completions/mfiutil

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
[[ $OSTYPE == *@(freebsd|dragonflybsd|darwin|linux|solaris)* ]] || return 1
2+
3+
_comp_cmd_mfiutil() {
4+
local cur prev words cword comp_args
5+
_comp_initialize -- "$@" || return
6+
7+
if [[ $cur == -* ]]; then
8+
# Complete global options
9+
local options="-u -d -e"
10+
case "$OSTYPE" in
11+
*freebsd*)
12+
options="$options -D -t"
13+
;;
14+
*dragonflybsd*|*solaris*)
15+
options="$options -t"
16+
;;
17+
esac
18+
local end_of_options=
19+
local w
20+
for w in "${words[@]:1:cword-1}"; do
21+
case "$w" in
22+
--)
23+
end_of_options=1
24+
break
25+
;;
26+
-*)
27+
;;
28+
*)
29+
end_of_options=1
30+
break
31+
;;
32+
esac
33+
done
34+
if [[ ! $end_of_options ]]; then
35+
_comp_compgen -- -W '$options'
36+
return
37+
fi
38+
fi
39+
40+
local REPLY
41+
_comp_count_args -a "-*[Dtu]"
42+
case $REPLY in
43+
0)
44+
# Complete argument to global options
45+
case "$prev" in
46+
-D)
47+
_comp_compgen_filedir
48+
;;
49+
-t)
50+
case "$OSTYPE" in
51+
*freebsd*|*dragonflybsd*)
52+
_comp_compgen -- -W 'mfi mrsas'
53+
;;
54+
esac
55+
;;
56+
esac
57+
;;
58+
1)
59+
_comp_compgen -- -W '
60+
version show fail good rebuild syspd drive start abort locate
61+
cache name volume clear create delete add remove patrol stop
62+
foreign flash bbu ctrlprop'
63+
;;
64+
2)
65+
case "$prev" in
66+
show)
67+
_comp_compgen -- -W '
68+
adapter battery config drives events firmware foreign
69+
logstate volumes patrol progress'
70+
;;
71+
drive)
72+
_comp_compgen -- -W 'progress clear'
73+
;;
74+
start)
75+
_comp_compgen -- -W 'rebuild patrol learn'
76+
;;
77+
abort)
78+
_comp_compgen -- -W 'rebuild'
79+
;;
80+
volume)
81+
_comp_compgen -- -W 'progress'
82+
;;
83+
create)
84+
_comp_compgen -- -W '
85+
jbod raid0 raid1 raid5 raid6 raid10 raid50 raid60 concat'
86+
;;
87+
patrol)
88+
_comp_compgen -- -W 'disable auto manual'
89+
;;
90+
stop)
91+
_comp_compgen -- -W 'patrol'
92+
;;
93+
foreign)
94+
_comp_compgen -- -W 'scan clear diag preview import'
95+
;;
96+
flash)
97+
_comp_compgen_filedir
98+
;;
99+
bbu)
100+
_comp_compgen -- -W 'learn-delay autolearn-mode bbu-mode'
101+
;;
102+
ctrlprop)
103+
_comp_compgen -- -W 'rebuild alarm'
104+
;;
105+
esac
106+
;;
107+
3)
108+
case "${words[cword-2]}.$prev" in
109+
locate.*)
110+
_comp_compgen -- -W 'on off'
111+
;;
112+
cache.*)
113+
_comp_compgen -- -W '
114+
enable disable reads writes write-back write-through
115+
read-ahead bad-bbu-write-cache write-cache'
116+
;;
117+
ctrlprop.alarm)
118+
_comp_compgen -- -W 'on off 1 0'
119+
;;
120+
esac
121+
;;
122+
esac
123+
}
124+
complete -F _comp_cmd_mfiutil mfiutil mrsasutil

test/t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ EXTRA_DIST = \
372372
test_mdtool.py \
373373
test_medusa.py \
374374
test_mencoder.py \
375+
test_mfiutil.py \
375376
test_mii_diag.py \
376377
test_mii_tool.py \
377378
test_minicom.py \

test/t/test_mfiutil.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
4+
class TestMfiUtil:
5+
@pytest.mark.complete("mfiutil -")
6+
def test_global_options(self, completion):
7+
assert completion
8+
9+
@pytest.mark.complete("mfiutil show ")
10+
def test_show_subcommand(self, completion):
11+
assert completion
12+
13+
@pytest.mark.complete("mfiutil show -")
14+
def test_options_after_subcommands(self, completion):
15+
assert not completion
16+
17+
@pytest.mark.complete("mfiutil -e show dri")
18+
def test_show_drives_subcommand_with_global_option(self, completion):
19+
assert completion == ["ves"]
20+
21+
@pytest.mark.complete("mfiutil locate 1 ")
22+
def test_locate_subcommand(self, completion):
23+
assert completion == ["off", "on"]

0 commit comments

Comments
 (0)