Files
modules/init/bash_completion
Xavier Delaruelle 20093d7218 Introduce 'test' command and mode
Add 'module test' command to trigger when called execution of a
ModulesTest procedure in target modulefile following same kind of
mechanism than 'module help'.

If ModulesTest procedure is missing from modulefile, a 'Unable to find
ModulesTest proc' message is displayed but no error code is set. If
ModulesTest procedure returns 1 (true), test is considered successful and
message 'Test result: PASS' is displayed. If ModulesTest returns no or
any other value, test is considered failed and message 'Test result:
FAIL' is displayed. In this case, module command exit in error.

Adapt bash and tcsh completion scripts for the new command. Describe new
command and new mode in docs.

Adapt existing non-regression tests and relative test modulefiles for
new command and new mode in 00-init, 50-cmds and 70-maint suites. Add
085-test tests in 70-maint to check coherent behavior of new command.
2017-04-30 19:00:18 +02:00

94 lines
3.0 KiB
Bash

#
# Bash commandline completion (bash 3.0 and above)
#
_module_avail() {
module avail -t 2>&1 | sed '
/^-\+/d; /^\s*$/d;
/->.*$/d;
/:$/d;
/:ERROR:/d;
s#^\(.*\)/\(.\+\)(.*default.*)#\1\n\1\/\2#;
s#(.*)$##g;
s#\s*$##g;
s#/*$##g;'
}
_module_savelist() {
module savelist -t 2>&1 | sed '
/Named collection list$/d;
/:$/d;
/:ERROR:/d;'
}
_module_not_yet_loaded() {
_module_avail | sort | sed -r "\%^(${LOADEDMODULES//:/|})$%d"
}
_module_long_arg_list() {
local cur="$1" i
if [[ ${COMP_WORDS[COMP_CWORD-2]} == sw* ]]
then
COMPREPLY=( $(compgen -W "$(_module_not_yet_loaded)" -- "$cur") )
return
fi
for ((i = COMP_CWORD - 1; i > 0; i--))
do case ${COMP_WORDS[$i]} in
add|load)
COMPREPLY=( $(compgen -W "$(_module_not_yet_loaded)" -- "$cur") )
break;;
rm|remove|unload|switch|swap)
COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") )
break;;
esac
done
}
_module() {
local cur="$2" prev="$3" cmds opts
COMPREPLY=()
cmds="add apropos aliases avail display help\
initadd initclear initlist initprepend initrm\
keyword list load path paths purge refresh reload restore\
rm save savelist saveshow saverm search show source swap\
switch test unload unuse use whatis"
opts="-D -h -V --debug --help --version"
list_opts="-l -t --long --terse"
avail_opts="-d -L -l -t --default --latest --long --terse"
case "$prev" in
add|load) COMPREPLY=( $(compgen -W "$(_module_not_yet_loaded)" -- "$cur") );;
avail) COMPREPLY=( $(compgen -W "$avail_opts $(_module_avail)" -- "$cur") );;
list|savelist) COMPREPLY=( $(compgen -W "$list_opts" -- "$cur") );;
restore|save|saveshow|saverm)
COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );;
rm|remove|unload|switch|swap)
COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") );;
unuse) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );;
use|*-a*) ;; # let readline handle the completion
display|help|show|test|whatis)
COMPREPLY=( $(compgen -W "$(_module_avail)" -- "$cur") );;
-h|--help|-V|--version|aliases|apropos|keyword|purge|refresh|reload|search|source)
;;
initadd|initclear|initlist|initprepend|initrm)
;;
*) if test $COMP_CWORD -gt 2
then
_module_long_arg_list "$cur"
else
case "$cur" in
# The mappings below are optional abbreviations for convenience
ls) COMPREPLY="list";; # map ls -> list
sw*) COMPREPLY="switch";;
-*) COMPREPLY=( $(compgen -W "$opts" -- "$cur") );;
*) COMPREPLY=( $(compgen -W "$opts $cmds" -- "$cur") );;
esac
fi;;
esac
}
complete -o default -F _module module