diff --git a/ext/bash/mco_completion.sh b/ext/bash/mco_completion.sh old mode 100755 new mode 100644 index 1ba7065f..f37b1d4a --- a/ext/bash/mco_completion.sh +++ b/ext/bash/mco_completion.sh @@ -14,7 +14,7 @@ _mco() { local count_noopt=${#noopt[@]} local cmd=${noopt[0]} - local agent=${noopt[1]} + local app=${noopt[1]} # A bug in the output of --help prevents # from parsing all options, so we list the common ones here @@ -24,29 +24,28 @@ _mco() { --wi --with-identity" if [ $COMP_CWORD -eq 1 ]; then - agents=$($cmd | sed -n 's@Known commands: @@p') - COMPREPLY=($(compgen -W "$agents" -- "$cur")) + apps=$($cmd completion --list-applications) + COMPREPLY=($(compgen -W "$apps" -- "$cur")) elif [ $COMP_CWORD -gt 1 ]; then - options="${common_options} $($cmd $agent --help | grep -o -- '-[^, ]\+')" + options="${common_options} $($cmd $app --help | grep -o -- '-[^, ]\+')" - if [ "x${agent}" = "xrpc" ]; then + if [ "x${app}" = "xrpc" ]; then if [[ $count_noopt -eq 2 || "x${prev}" = "x--agent" ]]; then # Complete with agents - agents=$(ls $libdir/mcollective/agent | sed -n 's@\.ddl@@p') + agents=$($cmd completion --list-agents) options="$options $agents" elif [[ $count_noopt -eq 3 || "x${prev}" = "x--action" ]]; then # Complete with agent actions rpcagent=${noopt[2]} - actions=$(sed -n "s@^action [\"']\([^\"']\+\).*@\1@p" \ - "$libdir/mcollective/agent/$rpcagent.ddl" 2>/dev/null) + actions=$($cmd completion --list-actions \ + --agent "$rpcagent") options="$options $actions" elif [ $count_noopt -gt 3 ]; then # Complete with key=value rpcagent=${noopt[2]} rpcaction=${noopt[3]} - inputs=$(sed -n "/^action [\"']${rpcaction}.*/,/^end$/p" \ - "$libdir/mcollective/agent/$rpcagent.ddl" 2>/dev/null | \ - sed -n 's@[\t ]*input[\t ]\+:\([^,]\+\),.*@\1=@p') + inputs=$($cmd completion --list-inputs \ + --agent "$rpcagent" --action "$rpcaction") options="$options $inputs" fi fi