Skip to content

Commit 695df5b

Browse files
authored
Merge pull request #1241 from Low-power/mfiutil
Add completion for mfiutil(8)
2 parents 13c9ea4 + cbd2661 commit 695df5b

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

completions/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ cross_platform = 2to3 \
262262
_mdbook \
263263
mdtool \
264264
medusa \
265+
mfiutil \
265266
mii-diag \
266267
mii-tool \
267268
minicom \
@@ -1276,6 +1277,8 @@ symlinks: $(DATA)
12761277
mdecrypt
12771278
$(ss) _mdbook \
12781279
_deno _diesel _dprint _starship
1280+
$(ss) mfiutil \
1281+
mrsasutil
12791282
$(ss) mplayer \
12801283
gmplayer kplayer mencoder mplayer2
12811284
$(ss) mutt \

completions/mfiutil

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