cli-completion : rewrite completely the program
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2321 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -1,41 +1,96 @@
|
|||||||
_cli.php()
|
_cli.php()
|
||||||
{
|
{
|
||||||
local cur prev opts base
|
|
||||||
COMPREPLY=()
|
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
||||||
|
|
||||||
|
local cur prev opts ante
|
||||||
|
COMPREPLY=()
|
||||||
if [ ! -x "$1" ]; then
|
if [ ! -x "$1" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# List of options (operations) available
|
# List of options (operations) available
|
||||||
opts="-h -expert -list -listmethods -listmethodsdetails"
|
opts="
|
||||||
controllers=$($1 -listonly)
|
-h
|
||||||
opts="$opts $controllers"
|
-expert
|
||||||
|
-list
|
||||||
if [ "${prev}" == "-list" ]; then
|
-listmethods
|
||||||
return 0
|
-listmethodsdetails"
|
||||||
elif [ "${prev}" == "-listmethods" ] ||
|
if [ "${COMP_WORDS[1]}" == "-expert" ]; then
|
||||||
[ "${prev}" == "-listmethodsdetails" ]; then
|
EXPERT="-expert"
|
||||||
# Display the available class available
|
unset COMP_WORDS[1]
|
||||||
local control=$($1 -listonly)
|
COMP_WORDS=("${COMP_WORDS[@]}")
|
||||||
COMPREPLY=( $(compgen -W "${control}" -- ${cur}) )
|
COMP_CWORD=${COMP_CWORD}-1
|
||||||
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
|
else
|
||||||
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
|
EXPERT=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
ante="${COMP_WORDS[COMP_CWORD-2]}"
|
||||||
|
LISTCLASSES=$($1 $EXPERT -listonly)
|
||||||
|
LISTCLASSESSLASH=${LISTCLASSES//\\/\\\\\\\\}
|
||||||
|
opts="$opts
|
||||||
|
$LISTCLASSESSLASH
|
||||||
|
"
|
||||||
|
read -r LISTCLASSESLINE <<< ${LISTCLASSES}
|
||||||
|
if [ "$3" == "-list" ]; then
|
||||||
|
# Do not take any option
|
||||||
|
COMPREPLY=()
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$3" == "-listmethods" ] ||
|
||||||
|
[ "$3" == "-listmethodsdetails" ]; then
|
||||||
|
# Display the available classes available
|
||||||
|
COMPREPLY=( $(compgen -W "${LISTCLASSESSLASH}" -- ${cur/\\/\\\\\\\\}) )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${COMP_WORDS[1]}" == "" ] ||
|
||||||
|
[ "${COMP_WORDS[1]+1}" != "" ] &&
|
||||||
|
[ "${COMP_WORDS[2]+1}" == "" ]; then
|
||||||
|
# Nothing provided or just the first parameter : display the classes and
|
||||||
|
# options
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur//\\/\\\\}) )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
CLASS="${COMP_WORDS[1]}"
|
||||||
|
CLASS=${CLASS//\\\\/\\}
|
||||||
|
|
||||||
|
# Bash Syntax : If the COMP_WORDS[2] exists, return 1, else return ""
|
||||||
|
if [ "${COMP_WORDS[1]+1}" != "" ] &&
|
||||||
|
[ "${COMP_WORDS[2]+1}" != "" ] &&
|
||||||
|
[ "${COMP_WORDS[3]+1}" == "" ]; then
|
||||||
|
# Class filled, check for the methods
|
||||||
|
if [[ " ${LISTCLASSESLINE} " =~ " ${CLASS} " ]]; then
|
||||||
|
# Previous was a valid class : display the methods available
|
||||||
|
local LISTMETHODS=$($1 $EXPERT -listmethodsonly "${CLASS}")
|
||||||
|
COMPREPLY=( $(compgen -W "${LISTMETHODS}" -- ${cur}) )
|
||||||
|
else
|
||||||
|
# Not a valid class : don't display anything
|
||||||
|
COMPREPLY=()
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${COMP_WORDS[1]+1}" != "" ] &&
|
||||||
|
[ "${COMP_WORDS[2]+1}" != "" ] &&
|
||||||
|
[ "${COMP_WORDS[3]+1}" != "" ]; then
|
||||||
|
# Class + method + first parameter available
|
||||||
|
local LISTMETHODS=$($1 $EXPERT -listmethodsonly "${CLASS}")
|
||||||
|
read -r LISTMETHODSLINE <<< ${LISTMETHODS}
|
||||||
|
METHOD=${COMP_WORDS[2]}
|
||||||
|
if [[ " ${LISTCLASSESLINE} " =~ " ${CLASS} " ]] &&
|
||||||
|
[[ " ${LISTMETHODSLINE} " =~ " ${METHOD} " ]]; then
|
||||||
|
# A Class and a method valids : propose the datas
|
||||||
|
# XXX : To be done
|
||||||
|
COMPREPLY=()
|
||||||
|
else
|
||||||
|
# Invalid class or method provided : don't display anything
|
||||||
|
COMPREPLY=()
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _cli.php cli.php
|
complete -F _cli.php cli.php
|
||||||
|
|||||||
Reference in New Issue
Block a user