Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Adapt bash completion for 2.0.0 usage format #42

Closed
wants to merge 3 commits into from
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 10 additions and 11 deletions. Show diff stats Hide diff stats

  1. +10 11 ext/bash/mco_completion.sh
21 ext/bash/mco_completion.sh
@@ -14,7 +14,7 @@ _mco() {
14 14
15 15 local count_noopt=${#noopt[@]}
16 16 local cmd=${noopt[0]}
17   - local agent=${noopt[1]}
  17 + local app=${noopt[1]}
18 18
19 19 # A bug in the output of --help prevents
20 20 # from parsing all options, so we list the common ones here
@@ -24,29 +24,28 @@ _mco() {
24 24 --wi --with-identity"
25 25
26 26 if [ $COMP_CWORD -eq 1 ]; then
27   - agents=$($cmd | sed -n 's@Known commands: @@p')
28   - COMPREPLY=($(compgen -W "$agents" -- "$cur"))
  27 + apps=$($cmd completion --list-applications)
  28 + COMPREPLY=($(compgen -W "$apps" -- "$cur"))
29 29 elif [ $COMP_CWORD -gt 1 ]; then
30   - options="${common_options} $($cmd $agent --help | grep -o -- '-[^, ]\+')"
  30 + options="${common_options} $($cmd $app --help | grep -o -- '-[^, ]\+')"
31 31
32   - if [ "x${agent}" = "xrpc" ]; then
  32 + if [ "x${app}" = "xrpc" ]; then
33 33 if [[ $count_noopt -eq 2 || "x${prev}" = "x--agent" ]]; then
34 34 # Complete with agents
35   - agents=$(ls $libdir/mcollective/agent | sed -n 's@\.ddl@@p')
  35 + agents=$($cmd completion --list-agents)
36 36 options="$options $agents"
37 37 elif [[ $count_noopt -eq 3 || "x${prev}" = "x--action" ]]; then
38 38 # Complete with agent actions
39 39 rpcagent=${noopt[2]}
40   - actions=$(sed -n "s@^action [\"']\([^\"']\+\).*@\1@p" \
41   - "$libdir/mcollective/agent/$rpcagent.ddl" 2>/dev/null)
  40 + actions=$($cmd completion --list-actions \
  41 + --agent "$rpcagent")
42 42 options="$options $actions"
43 43 elif [ $count_noopt -gt 3 ]; then
44 44 # Complete with key=value
45 45 rpcagent=${noopt[2]}
46 46 rpcaction=${noopt[3]}
47   - inputs=$(sed -n "/^action [\"']${rpcaction}.*/,/^end$/p" \
48   - "$libdir/mcollective/agent/$rpcagent.ddl" 2>/dev/null | \
49   - sed -n 's@[\t ]*input[\t ]\+:\([^,]\+\),.*@\1=@p')
  47 + inputs=$($cmd completion --list-inputs \
  48 + --agent "$rpcagent" --action "$rpcaction")
50 49 options="$options $inputs"
51 50 fi
52 51 fi

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.