Skip to content

Commit

Permalink
14196 - Add bash completion script for mco
Browse files Browse the repository at this point in the history
Make use of the completion helper app in the bash completion script
  • Loading branch information
raphink authored and ripienaar committed May 29, 2012
1 parent f423f16 commit 160a934
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions ext/bash/mco_completion.sh 100755 → 100644
Expand Up @@ -14,7 +14,7 @@ _mco() {


local count_noopt=${#noopt[@]} local count_noopt=${#noopt[@]}
local cmd=${noopt[0]} local cmd=${noopt[0]}
local agent=${noopt[1]} local app=${noopt[1]}


# A bug in the output of --help prevents # A bug in the output of --help prevents
# from parsing all options, so we list the common ones here # from parsing all options, so we list the common ones here
Expand All @@ -24,29 +24,28 @@ _mco() {
--wi --with-identity" --wi --with-identity"


if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
agents=$($cmd | sed -n 's@Known commands: @@p') apps=$($cmd completion --list-applications)
COMPREPLY=($(compgen -W "$agents" -- "$cur")) COMPREPLY=($(compgen -W "$apps" -- "$cur"))
elif [ $COMP_CWORD -gt 1 ]; then 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 if [[ $count_noopt -eq 2 || "x${prev}" = "x--agent" ]]; then
# Complete with agents # Complete with agents
agents=$(ls $libdir/mcollective/agent | sed -n 's@\.ddl@@p') agents=$($cmd completion --list-agents)
options="$options $agents" options="$options $agents"
elif [[ $count_noopt -eq 3 || "x${prev}" = "x--action" ]]; then elif [[ $count_noopt -eq 3 || "x${prev}" = "x--action" ]]; then
# Complete with agent actions # Complete with agent actions
rpcagent=${noopt[2]} rpcagent=${noopt[2]}
actions=$(sed -n "s@^action [\"']\([^\"']\+\).*@\1@p" \ actions=$($cmd completion --list-actions \
"$libdir/mcollective/agent/$rpcagent.ddl" 2>/dev/null) --agent "$rpcagent")
options="$options $actions" options="$options $actions"
elif [ $count_noopt -gt 3 ]; then elif [ $count_noopt -gt 3 ]; then
# Complete with key=value # Complete with key=value
rpcagent=${noopt[2]} rpcagent=${noopt[2]}
rpcaction=${noopt[3]} rpcaction=${noopt[3]}
inputs=$(sed -n "/^action [\"']${rpcaction}.*/,/^end$/p" \ inputs=$($cmd completion --list-inputs \
"$libdir/mcollective/agent/$rpcagent.ddl" 2>/dev/null | \ --agent "$rpcagent" --action "$rpcaction")
sed -n 's@[\t ]*input[\t ]\+:\([^,]\+\),.*@\1=@p')
options="$options $inputs" options="$options $inputs"
fi fi
fi fi
Expand Down

0 comments on commit 160a934

Please sign in to comment.