1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#/usr/bin/env bash
# COMP_WORDS contains
# at index 0 the executable name (pgagroal-cli)
# at index 1 the command name (e.g., flush)
# at index 2, if required, the subcommand name (e.g., all)
pgagroal_cli_completions()
{
if [ "${#COMP_WORDS[@]}" == "2" ]; then
# main completion: the user has specified nothing at all
# or a single word, that is a command
COMPREPLY=($(compgen -W "flush ping enable disable shutdown status switch-to conf clear" "${COMP_WORDS[1]}"))
else
# the user has specified something else
# subcommand required?
case ${COMP_WORDS[1]} in
flush)
COMPREPLY+=($(compgen -W "gracefully idle all" "${COMP_WORDS[2]}"))
;;
shutdown)
COMPREPLY+=($(compgen -W "gracefully immediate cancel" "${COMP_WORDS[2]}"))
;;
clear)
COMPREPLY+=($(compgen -W "server prometheus" "${COMP_WORDS[2]}"))
;;
conf)
COMPREPLY+=($(compgen -W "reload get set ls alias" "${COMP_WORDS[2]}"))
;;
status)
COMPREPLY+=($(compgen -W "details" "${COMP_WORDS[2]}"))
esac
fi
}
pgagroal_admin_completions()
{
if [ "${#COMP_WORDS[@]}" == "2" ]; then
# main completion: the user has specified nothing at all
# or a single word, that is a command
COMPREPLY=($(compgen -W "master-key user" "${COMP_WORDS[1]}"))
else
# the user has specified something else
# subcommand required?
case ${COMP_WORDS[1]} in
user)
COMPREPLY+=($(compgen -W "add del edit ls" "${COMP_WORDS[2]}"))
;;
esac
fi
}
# install the completion functions
complete -F pgagroal_cli_completions pgagroal-cli
complete -F pgagroal_admin_completions pgagroal-admin
|