Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add a bash_completion script for mco #5

Closed
wants to merge 3 commits into from

1 participant

Raphaël Pinson
Raphaël Pinson

This is a very basic bash completion script for mco. It only completes on agent names and options (even specific ones) by parsing mco's help output.

It scales with new agents/options, and doesn't need to know about plugin paths.

Raphaël Pinson

Merged in puppetlabs/marionette-collective already.

Raphaël Pinson raphink closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 11 deletions.
  1. +10 −11 ext/bash/mco_completion.sh
21 ext/bash/mco_completion.sh
View
@@ -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
Something went wrong with that request. Please try again.