From 2fef892201db3656076e20ecc4961db8a7aa7fe3 Mon Sep 17 00:00:00 2001 From: Bruno Cornec Date: Thu, 23 Mar 2017 00:09:16 +0100 Subject: [PATCH] Fix auto completion for erdfish-client - Adds support for: - all options (-- and -) - all commands and subcommands - manager completion Change-Id: Icb074364795222428dac540224bd389257d0d2a9 --- .../etc/bash_completion.d/redfish-client.bash | 64 +++++++++++++++++-- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/redfish-client/etc/bash_completion.d/redfish-client.bash b/redfish-client/etc/bash_completion.d/redfish-client.bash index d1f739e..b435913 100644 --- a/redfish-client/etc/bash_completion.d/redfish-client.bash +++ b/redfish-client/etc/bash_completion.d/redfish-client.bash @@ -1,11 +1,61 @@ -_redfish-client_complete_baseopts() +_redfish-client() { - case $2 in + local cur prev opts + COMPREPLY=() + cfgfile=$HOME/.redfish/inventory + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="--help -h --insecure --debug --inventory -i --debugfile --libdebugfile + --config -c --version" + cmds="config manager chassis system" + confcmds="add del modify show showall" + ocmds="getinfo" + # done once as used a lot + mngrs=`redfish-client config show | tail -n +2` - --help|-h) - return 0 - ;; + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi - esac - return 1 + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) ) + elif [ $COMP_CWORD -eq 2 ]; then + case "${prev}" in + config) + COMPREPLY=( $(compgen -W "${confcmds}" -- ${cur}) ) + return 0 + ;; + *) + COMPREPLY=( $(compgen -W "${ocmds}" -- ${cur}) ) + return 0 + ;; + esac + + elif [ $COMP_CWORD -eq 3 ]; then + if [ "${COMP_WORDS[COMP_CWORD-2]}" = "config" ]; then + case "${prev}" in + del|modify) + COMPREPLY=( $(compgen -W "${mngrs}" -- ${cur}) ) + return 0 + ;; + esac + else + # all other cases are getinfo manager + case "${prev}" in + getinfo) + COMPREPLY=( $(compgen -W "${mngrs}" -- ${cur}) ) + return 0 + ;; + esac + fi + + elif [ $COMP_CWORD -eq 4 ]; then + if [ "${COMP_WORDS[COMP_CWORD-3]}" = "config" ] && + [ "${COMP_WORDS[COMP_CWORD-2]}" = "modify" ]; then + COMPREPLY=( $(compgen -W "manager_name url login password" -- ${cur}) ) + return 0 + fi + fi } +complete -F _redfish-client redfish-client