Files
DomFramework/docs/cli-completion
2014-08-18 12:00:52 +00:00

43 lines
1.2 KiB
Plaintext

_cli.php()
{
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ ! -x "$1" ]; then
return 0
fi
# List of options (operations) available
opts="-h -expert -list -listmethods -listmethodsdetails"
controllers=$($1 -listonly)
opts="$opts $controllers"
if [ "${prev}" == "-list" ]; then
return 0
elif [ "${prev}" == "-listmethods" ] ||
[ "${prev}" == "-listmethodsdetails" ]; then
# Display the available class available
local control=$($1 -listonly)
COMPREPLY=( $(compgen -W "${control}" -- ${cur}) )
return 0
elif [ `$1 -listonly | grep -qx "${prev}" ; echo $?` == 0 ]; then
# Previous was a class : display the methods available
local methods=$($1 -listmethodsonly ${prev})
COMPREPLY=( $(compgen -W "${methods}" -- ${cur}) )
return 0
elif [ `$1 -listonly | grep -qx "${COMP_WORDS[COMP_CWORD-2]}" ; echo $?` == 0 ] &&
[ `$1 -listonly | grep -qx ${prev}" ; echo $?` == 0 ]; then
# A Class and a method available : propose the datas
# XXX : To be done
return 0
else
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
fi
return 0
}
complete -F _cli.php cli.php
complete -F _cli.php ./cli/cli.php