Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

14196 - Add bash completion script for mco

Make use of the completion helper app in the bash completion script
  • Loading branch information...
commit 160a934219784edc70888e24ae079edfc523f5cf 1 parent f423f16
@raphink raphink authored ripienaar committed
Showing with 10 additions and 11 deletions.
  1. +10 −11 ext/bash/mco_completion.sh
View
21 ext/bash/mco_completion.sh 100755 → 100644
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.