mirror of
https://github.com/clap-rs/clap
synced 2025-01-09 11:18:45 +00:00
129 lines
3.7 KiB
Text
129 lines
3.7 KiB
Text
|
_my-app() {
|
||
|
local i cur prev opts cmds
|
||
|
COMPREPLY=()
|
||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||
|
cmd=""
|
||
|
opts=""
|
||
|
|
||
|
for i in ${COMP_WORDS[@]}
|
||
|
do
|
||
|
case "${i}" in
|
||
|
"$1")
|
||
|
cmd="my__app"
|
||
|
;;
|
||
|
help)
|
||
|
cmd+="__help"
|
||
|
;;
|
||
|
some_cmd)
|
||
|
cmd+="__some_cmd"
|
||
|
;;
|
||
|
sub_cmd)
|
||
|
cmd+="__sub_cmd"
|
||
|
;;
|
||
|
test)
|
||
|
cmd+="__test"
|
||
|
;;
|
||
|
*)
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
case "${cmd}" in
|
||
|
my__app)
|
||
|
opts="-h -V -C -c --help --version --conf --config <file> first second test some_cmd help"
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
my__app__help)
|
||
|
opts="<SUBCOMMAND>..."
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
my__app__some_cmd)
|
||
|
opts="-h -V --help --version sub_cmd help"
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
my__app__some_cmd__help)
|
||
|
opts="-h -V --help --version <SUBCOMMAND>..."
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
my__app__some_cmd__sub_cmd)
|
||
|
opts="-h -V --config --help --version"
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
--config)
|
||
|
COMPREPLY=($(compgen -W "" -- "${cur}"))
|
||
|
return 0
|
||
|
;;
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
my__app__test)
|
||
|
opts="-h -V --case --help --version"
|
||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
fi
|
||
|
case "${prev}" in
|
||
|
--case)
|
||
|
COMPREPLY=($(compgen -f "${cur}"))
|
||
|
return 0
|
||
|
;;
|
||
|
*)
|
||
|
COMPREPLY=()
|
||
|
;;
|
||
|
esac
|
||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||
|
return 0
|
||
|
;;
|
||
|
esac
|
||
|
}
|
||
|
|
||
|
complete -F _my-app -o bashdefault -o default my-app
|