Add bash-completion support to CLI

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1723 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-08-18 12:00:52 +00:00
parent a886b63eb3
commit 53f192f23c
2 changed files with 43 additions and 0 deletions

1
debian/install vendored
View File

@@ -1,3 +1,4 @@
*.php usr/share/php/domframework *.php usr/share/php/domframework
examples usr/share/doc/domframework examples usr/share/doc/domframework
docs/* usr/share/doc/domframework docs/* usr/share/doc/domframework
docs/cli-completion usr/share/bash-completion/completions

42
docs/cli-completion Normal file
View File

@@ -0,0 +1,42 @@
_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