quota-tools: Use _parse_help, add bunch of option completions and basic test cases.
This commit is contained in:
parent
997ecac0f0
commit
174d40ecff
@ -8,7 +8,7 @@ _user_or_group()
|
|||||||
|
|
||||||
# complete on groups if -g was given
|
# complete on groups if -g was given
|
||||||
for (( i=1; i < cword; i++ )); do
|
for (( i=1; i < cword; i++ )); do
|
||||||
if [[ "${words[i]}" == -g ]]; then
|
if [[ "${words[i]}" == -@(g|-group) ]]; then
|
||||||
COMPREPLY=( $( compgen -g -- "$cur" ) )
|
COMPREPLY=( $( compgen -g -- "$cur" ) )
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
@ -18,6 +18,14 @@ _user_or_group()
|
|||||||
COMPREPLY=( $( compgen -u -- "$cur" ) )
|
COMPREPLY=( $( compgen -u -- "$cur" ) )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_quota_parse_help()
|
||||||
|
{
|
||||||
|
local opts=$( _parse_help "$1" )
|
||||||
|
[[ $opts ]] || opts=$( _parse_usage "$1" ) # non-GNU?
|
||||||
|
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
|
||||||
|
[[ $COMPREPLY == *= ]] && compopt -o nospace
|
||||||
|
}
|
||||||
|
|
||||||
_quota_formats()
|
_quota_formats()
|
||||||
{
|
{
|
||||||
COMPREPLY=( $( compgen -W 'vfsold vfsv0 rpc xfs' -- "$cur" ) )
|
COMPREPLY=( $( compgen -W 'vfsold vfsv0 rpc xfs' -- "$cur" ) )
|
||||||
@ -41,15 +49,15 @@ _quota()
|
|||||||
_quota_formats
|
_quota_formats
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
-h|--help|-V|--version)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
$split && return 0
|
$split && return 0
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '-F --format -g --group -u --user -v \
|
_quota_parse_help "$1"
|
||||||
--verbose -s --human-readable -p --raw-grace -i --no-autofs -l \
|
|
||||||
--local-only -A --all-nfs -m --no-mixed-pathnames -q --quiet -Q \
|
|
||||||
--quiet-refuse -w --no-wrap' -- "$cur" ) )
|
|
||||||
else
|
else
|
||||||
_user_or_group
|
_user_or_group
|
||||||
fi
|
fi
|
||||||
@ -66,16 +74,21 @@ _setquota()
|
|||||||
_quota_formats
|
_quota_formats
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
-p|--prototype)
|
||||||
|
_user_or_group
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-h|--help|-V|--version)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
$split && return 0
|
$split && return 0
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '-r --remote -m --no-mixed-pathnames \
|
_quota_parse_help "$1"
|
||||||
-F --format -g --group -u --user -p --prototype -b --batch \
|
|
||||||
-c --continue-batch -t --edit-period -T --edit-times -a --all' \
|
|
||||||
-- "$cur" ) )
|
|
||||||
else
|
else
|
||||||
|
local args
|
||||||
_count_args
|
_count_args
|
||||||
|
|
||||||
case $args in
|
case $args in
|
||||||
@ -105,14 +118,19 @@ _edquota()
|
|||||||
_filesystems
|
_filesystems
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
-p|--prototype)
|
||||||
|
_user_or_group
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-h|--help|-V|--version)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
$split && return 0
|
$split && return 0
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '-r --remote -m --no-mixed-pathnames \
|
_quota_parse_help "$1"
|
||||||
-g --group -u --user -p --prototype -F --format -f --filesystem \
|
|
||||||
-t --edit-period -T --edit-times' -- "$cur" ) )
|
|
||||||
else
|
else
|
||||||
_user_or_group
|
_user_or_group
|
||||||
fi
|
fi
|
||||||
@ -129,29 +147,7 @@ _quotacheck()
|
|||||||
_quota_formats
|
_quota_formats
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
-h|--help|-V|--version)
|
||||||
|
|
||||||
$split && return 0
|
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
|
||||||
COMPREPLY=( $( compgen -W '-b --backup -v --verbose -d --debug \
|
|
||||||
-g --group -u --user -c --create-files -f --force -i \
|
|
||||||
--interactive -n --use-first-dquot -M --try-remount -m \
|
|
||||||
--no-remount -R --exclude-root -F --format -a --all' -- "$cur" ) )
|
|
||||||
else
|
|
||||||
_filesystems
|
|
||||||
fi
|
|
||||||
} &&
|
|
||||||
complete -F _quotacheck -o default quotacheck
|
|
||||||
|
|
||||||
_repquota()
|
|
||||||
{
|
|
||||||
local cur prev words cword split
|
|
||||||
_init_completion -s || return
|
|
||||||
|
|
||||||
case $prev in
|
|
||||||
-F|--format)
|
|
||||||
_quota_formats
|
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -159,44 +155,18 @@ _repquota()
|
|||||||
$split && return 0
|
$split && return 0
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '-a --all -v --verbose -s --human-readable \
|
_quota_parse_help "$1"
|
||||||
-c --batch-translation -C --no-batch-translation -t \
|
|
||||||
--truncate-names -n --no-names -p --raw-grace -i --no-autofs \
|
|
||||||
-u --user -g --group -F --format' -- "$cur" ) )
|
|
||||||
else
|
else
|
||||||
_filesystems
|
_filesystems
|
||||||
fi
|
fi
|
||||||
} &&
|
} &&
|
||||||
complete -F _repquota -o default repquota
|
complete -F _quotacheck -o default quotacheck repquota
|
||||||
|
|
||||||
_quotaon()
|
_quotaon()
|
||||||
{
|
{
|
||||||
local cur prev words cword split
|
local cur prev words cword split
|
||||||
_init_completion -s || return
|
_init_completion -s || return
|
||||||
|
|
||||||
case $prev in
|
|
||||||
-F|--format)
|
|
||||||
_quota_formats
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
$split && return 0
|
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
|
||||||
COMPREPLY=( $( compgen -W '-a --all -v --verbose -u --user \
|
|
||||||
-g --group -f --off -p --print-state -F --format' -- "$cur" ) )
|
|
||||||
else
|
|
||||||
_filesystems
|
|
||||||
fi
|
|
||||||
} &&
|
|
||||||
complete -F _quotaon -o default quotaon
|
|
||||||
|
|
||||||
_quotaoff()
|
|
||||||
{
|
|
||||||
local cur prev words cword split
|
|
||||||
_init_completion -s || return
|
|
||||||
|
|
||||||
case $prev in
|
case $prev in
|
||||||
-F|--format)
|
-F|--format)
|
||||||
_quota_formats
|
_quota_formats
|
||||||
@ -206,19 +176,20 @@ _quotaoff()
|
|||||||
COMPREPLY=( $( compgen -W 'delete enforce' -- "$cur" ) )
|
COMPREPLY=( $( compgen -W 'delete enforce' -- "$cur" ) )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
-h|--help|-V|--version)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
$split && return 0
|
$split && return 0
|
||||||
|
|
||||||
if [[ "$cur" == -* ]]; then
|
if [[ "$cur" == -* ]]; then
|
||||||
COMPREPLY=( $( compgen -W '-a --all -v --verbose -u --user \
|
_quota_parse_help "$1"
|
||||||
-g --group -p --print-state -x --xfs-command -F --format' \
|
|
||||||
-- "$cur" ) )
|
|
||||||
else
|
else
|
||||||
_filesystems
|
_filesystems
|
||||||
fi
|
fi
|
||||||
} &&
|
} &&
|
||||||
complete -F _quotaoff -o default quotaoff
|
complete -F _quotaon -o default quotaon quotaoff
|
||||||
|
|
||||||
# Local variables:
|
# Local variables:
|
||||||
# mode: shell-script
|
# mode: shell-script
|
||||||
|
1
test/completion/quota.exp
Normal file
1
test/completion/quota.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
assert_source_completions quota
|
1
test/completion/quotacheck.exp
Normal file
1
test/completion/quotacheck.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
assert_source_completions quotacheck
|
1
test/completion/quotaon.exp
Normal file
1
test/completion/quotaon.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
assert_source_completions quotaon
|
1
test/completion/setquota.exp
Normal file
1
test/completion/setquota.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
assert_source_completions setquota
|
20
test/lib/completions/quota.exp
Normal file
20
test/lib/completions/quota.exp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
proc setup {} {
|
||||||
|
save_env
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
proc teardown {} {
|
||||||
|
assert_env_unmodified
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setup
|
||||||
|
|
||||||
|
|
||||||
|
assert_complete_any "quota "
|
||||||
|
|
||||||
|
|
||||||
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
|
teardown
|
20
test/lib/completions/quotacheck.exp
Normal file
20
test/lib/completions/quotacheck.exp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
proc setup {} {
|
||||||
|
save_env
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
proc teardown {} {
|
||||||
|
assert_env_unmodified
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setup
|
||||||
|
|
||||||
|
|
||||||
|
assert_complete_any "quotacheck "
|
||||||
|
|
||||||
|
|
||||||
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
|
teardown
|
20
test/lib/completions/quotaon.exp
Normal file
20
test/lib/completions/quotaon.exp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
proc setup {} {
|
||||||
|
save_env
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
proc teardown {} {
|
||||||
|
assert_env_unmodified
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setup
|
||||||
|
|
||||||
|
|
||||||
|
assert_complete_any "quotaon "
|
||||||
|
|
||||||
|
|
||||||
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
|
teardown
|
20
test/lib/completions/setquota.exp
Normal file
20
test/lib/completions/setquota.exp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
proc setup {} {
|
||||||
|
save_env
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
proc teardown {} {
|
||||||
|
assert_env_unmodified
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setup
|
||||||
|
|
||||||
|
|
||||||
|
assert_complete_any "setquota "
|
||||||
|
|
||||||
|
|
||||||
|
sync_after_int
|
||||||
|
|
||||||
|
|
||||||
|
teardown
|
Loading…
x
Reference in New Issue
Block a user