2b2fb0a0e91bdacff6b2820cb014e4f759fe5de0
[packages/precise/mcollective.git] / ext / zsh / _mco
1 #compdef mco
2
3 # completion for the mcollective cli.
4 #
5 # for the main mco application it will complete
6 # the list of available applications
7 #
8 # for the rpc application it will complete first
9 # the list of agents, then actions and then each
10 # input.
11 #
12 # For all other applications it will just complete
13 # the common command line options, to add another
14 # application simply define a function called
15 # _mco_application_foo() for the foo application
16
17 _mco() {
18   if (( CURRENT > 2 )); then
19     local application=${words[2]}
20
21     shift words
22
23     args=({-W,--with}'[Combined class and fact filter]' \
24           {-S,--select}'[Select filter]' \
25           {-F,--wf,--with-fact}'[Fact filter]' \
26           {-C,--wc,--with-class}'[Class filter]' \
27           {-A,--wa,--with-agent}'[Agent filter]' \
28           {-I,--wi,--with-identity}'[Identity filter]' \
29           {-T,--target}'[Target collective]' \
30           {--dm,--disc-method}'[Which discovery method to use]' \
31           {--do,--disc-option}'[Options to pass to the discovery method]' \
32           {--dt,--discovery-timeout}'[Discovery timeout]' \
33           {-t,--timeout}'[Command Timeout]' \
34           {-q,--quiet}'[Surpress verbose output]' \
35           {-c,--config}'[Path to the config file]' \
36           {-v,--verbose}'[Be verbose]' \
37           {-h,--help}'[Show complete help message]' \
38           '--nodes[List of nodes to address]' \
39           '--ttl[Time To Live for the request]' \
40           '--reply-to[Custom reply target]')
41
42     curcontext="${curcontext%:*:*}:mco-${application}"
43
44     if (( $+functions[_mco_application_$application] > 0 ));then
45       _mco_application_$application
46     fi
47
48     _arguments -s : $args
49   else
50     local -a cmdlist
51     _call_program mco-list-applications mco completion --list-applications -v | while read -A hline; do
52       cmdlist=($cmdlist "${hline}")
53     done
54
55     curcontext="${curcontext%:*:*}:mco-applications"
56
57     _describe -t mco-application 'MCollective applications' cmdlist
58   fi
59 }
60
61 _mco_application_rpc() {
62   local -a clist
63
64   if (( CURRENT == 3 )); then
65     _call_program mco-list-agents mco completion --list-agents -v | while read -A hline; do
66       clist=($clist "${hline}")
67     done
68
69     _describe -t mco-agents "MCollective agents" clist
70   elif (( CURRENT == 4 )); then
71     _call_program mco-list-actions mco completion --list-actions --agent=${words[2]} -v | while read -A hline; do
72       clist=($clist "${hline}")
73     done
74
75     _describe -t mco-actions "${words[2]} actions" clist
76
77   elif (( CURRENT > 4 )); then
78     _call_program mco-list-inputs mco completion --list-inputs --action=${words[3]} --agent=${words[2]} -v | while read hline; do
79       clist=($clist $hline)
80     done
81
82     _describe -t mco-inputs "${words[3]} inputs" clist -S =
83   fi
84
85   args+=(
86         {--np,--no-progress}'[Do not show the progress bar]' \
87         {--nr,--no-results}'[Do not process results, just send request]' \
88         {-1,--one}'[Send request to only one discovered node]' \
89         '--batch[Do request in batches]' \
90         '--batch-sleep[Sleep time between batches]' \
91         {--ln,--limit-nodes}'[Only send the request to a certain number of discovered nodes]' \
92         {-j,--json}'[Output result as JSON data]'
93        )
94 }