-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,7 @@ bashcomp_DATA = 2to3 \ | |
_mdbook \ | ||
mdtool \ | ||
medusa \ | ||
mfiutil \ | ||
mii-diag \ | ||
mii-tool \ | ||
minicom \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
[[ $OSTYPE == *@(freebsd|dragonflybsd|darwin|linux|solaris)* ]] || return 1 | ||
|
||
_complete_mfiutil() { | ||
local cur prev words cword comp_args | ||
_comp_initialize -- "$@" || return | ||
|
||
if [[ $cur == -* ]]; then | ||
# Complete global options | ||
local options="-u -d -e" | ||
case "$OSTYPE" in | ||
*freebsd*) | ||
options="$options -D -t" | ||
;; | ||
*dragonflybsd*|*solaris*) | ||
options="$options -t" | ||
;; | ||
esac | ||
local end_of_options= | ||
local w | ||
for w in "${words[@]:1:cword-1}"; do | ||
case "$w" in | ||
--) | ||
end_of_options=1 | ||
break | ||
;; | ||
-*) | ||
;; | ||
*) | ||
end_of_options=1 | ||
break | ||
;; | ||
esac | ||
done | ||
if [ -z "$end_of_options" ]; then | ||
_comp_compgen -- -W '$options' | ||
return | ||
fi | ||
fi | ||
|
||
local REPLY | ||
_comp_count_args -a "-*[Dtu]" | ||
case $REPLY in | ||
0) | ||
# Complete argument to global options | ||
case "$prev" in | ||
-D) | ||
_filedir | ||
;; | ||
-t) | ||
case "$OSTYPE" in | ||
*freebsd*|*dragonflybsd*) | ||
_comp_compgen -- -W 'mfi mrsas' | ||
;; | ||
esac | ||
;; | ||
esac | ||
;; | ||
1) | ||
_comp_compgen -- -W ' | ||
version show fail good rebuild syspd drive start abort locate | ||
cache name volume clear create delete add remove patrol stop | ||
foreign flash bbu ctrlprop' | ||
;; | ||
2) | ||
case "$prev" in | ||
show) | ||
_comp_compgen -- -W ' | ||
adapter battery config drives events firmware foreign | ||
logstate volumes patrol progress' | ||
;; | ||
drive) | ||
_comp_compgen -- -W 'progress clear' | ||
;; | ||
start) | ||
_comp_compgen -- -W 'rebuild patrol learn' | ||
;; | ||
abort) | ||
_comp_compgen -- -W 'rebuild' | ||
;; | ||
volume) | ||
_comp_compgen -- -W 'progress' | ||
;; | ||
create) | ||
_comp_compgen -- -W ' | ||
jbod raid0 raid1 raid5 raid6 raid10 raid50 raid60 concat' | ||
;; | ||
patrol) | ||
_comp_compgen -- -W 'disable auto manual' | ||
;; | ||
stop) | ||
_comp_compgen -- -W 'patrol' | ||
;; | ||
foreign) | ||
_comp_compgen -- -W 'scan clear diag preview import' | ||
;; | ||
flash) | ||
_filedir | ||
;; | ||
bbu) | ||
_comp_compgen -- -W 'learn-delay autolearn-mode bbu-mode' | ||
;; | ||
ctrlprop) | ||
_comp_compgen -- -W 'rebuild alarm' | ||
;; | ||
esac | ||
;; | ||
3) | ||
case "${words[cword-2]}.$prev" in | ||
locate.*) | ||
_comp_compgen -- -W 'on off' | ||
;; | ||
cache.*) | ||
_comp_compgen -- -W ' | ||
enable disable reads writes write-back write-through | ||
read-ahead bad-bbu-write-cache write-cache' | ||
;; | ||
ctrlprop.alarm) | ||
_comp_compgen -- -W 'on off 1 0' | ||
;; | ||
esac | ||
;; | ||
esac | ||
} | ||
complete -F _complete_mfiutil mfiutil mrsasutil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
|
||
|
||
class TestMfiUtil: | ||
@pytest.mark.complete("mfiutil show ") | ||
def test_basic(self, completion): | ||
assert completion | ||
|
||
@pytest.mark.complete("mfiutil -") | ||
def test_global_options(self, completion): | ||
assert completion | ||
|
||
@pytest.mark.complete("mfiutil show -") | ||
def test_options_after_subcommands(self, completion): | ||
assert not completion | ||
|
||
@pytest.mark.complete("mfiutil locate 1 ") | ||
def test_locate_subcommand(self, completion): | ||
assert completion == ["off", "on"] |