From 53f192f23c812b2e938d37332eac3deee4c52e0a Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 18 Aug 2014 12:00:52 +0000 Subject: [PATCH] Add bash-completion support to CLI git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1723 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- debian/install | 1 + docs/cli-completion | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 docs/cli-completion diff --git a/debian/install b/debian/install index ca9a131..8a6f7ad 100644 --- a/debian/install +++ b/debian/install @@ -1,3 +1,4 @@ *.php usr/share/php/domframework examples usr/share/doc/domframework docs/* usr/share/doc/domframework +docs/cli-completion usr/share/bash-completion/completions diff --git a/docs/cli-completion b/docs/cli-completion new file mode 100644 index 0000000..ad99712 --- /dev/null +++ b/docs/cli-completion @@ -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