225425fe091ca052997833279ccc08643818c24a

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

Fix target_list creation. Supports fabric 1 and 2

Diff

 1diff --git a/plugins/fabric/_fab b/plugins/fabric/_fab
 2index 79d596ed6f2fed9536a2abfd7c2fb7ffd7ba8a94..89e73e58bfa605d81662e6f2ba554a47d3dc00b7 100644
 3--- a/plugins/fabric/_fab
 4+++ b/plugins/fabric/_fab
 5@@ -4,13 +4,19 @@
 6 local curcontext=$curcontext state line
 7 declare -A opt_args
 8 
 9-declare target_list
10-IFS="$(printf '\n+')" target_list=($(fab -l | awk '{
11-    if(NR > 2)
12-        printf "%s:%s\n", $1, substr($0, index($0, $2))
13-}' 2>/dev/null))
14+declare -a target_list
15+target_list=("${(@f)$(fab -l 2>/dev/null | awk '{
16+    if (NF == 0 || NR == 1) return
17+    if (NF < 2) print $1
18+    else {
19+        docstring=substr($0, index($0,$2))
20+        gsub(":", "\\:", docstring)
21+        print $1":"docstring
22+    }
23+}')}")
24 
25-_targets() {
26+_fab_targets() {
27+    [[ -n "$target_list" ]] || return
28     _describe -t commands "fabric targets" target_list
29 }
30 
31@@ -31,7 +37,7 @@ _arguments -w -S -C \
32   '(-)--shortlist[print non-verbose list of possible commands and exit]: :->noargs' \
33   '(--reject-unknown-hosts)--reject-unknown-hosts[reject unknown hosts]' \
34   '(--no-pty)--no-pty[do not use pseudo-terminal in run/sudo]' \
35-  "(-d+ --display=-)"{-d+,--display=-}"[print detailed info about a given command]: :_targets" \
36+  "(-d+ --display=-)"{-d+,--display=-}"[print detailed info about a given command]: :_fab_targets" \
37   '(-D --disable-known-hosts)'{-D,--disable-known-hosts}'[do not load user known_hosts file]' \
38   '(-r --reject-unknown-hosts)'{-r,--reject-unknown-hosts}'[reject unknown hosts]' \
39   '(-u+ --user=-)'{-u+,--user=-}'[username to use when connecting to remote hosts]: :' \
40@@ -56,7 +62,7 @@ if [[ CURRENT -ge 1 ]]; then
41         levels)
42             _describe -t commands "output levels" output_levels;;
43         *)
44-            _targets;;
45+            _fab_targets;;
46     esac
47 
48     return