]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat cli : Add options to bash completion script
authorSteven Hardy <shardy@redhat.com>
Wed, 16 May 2012 08:36:43 +0000 (09:36 +0100)
committerSteven Hardy <shardy@redhat.com>
Wed, 16 May 2012 08:48:37 +0000 (09:48 +0100)
Ref #87 add completion of long-format options, align the command options with
the "heat help" option

Signed-off-by: Steven Hardy <shardy@redhat.com>
etc/bash_completion.d/heat

index 0cde40606d0e3ad91dafcaff1b54819edf383f4e..4b04ef52e7acfdfb0f0a43bcf152112ade2b2b4d 100644 (file)
@@ -4,15 +4,19 @@ _heat()
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     prev="${COMP_WORDS[COMP_CWORD-1]}"
-    opts=`for i in $(heat --help | grep -A100 "^Commands" | grep -B100 "^Options" | grep "^\s*[a-z]" | awk '{print $1}'); do echo $i; done`
 
-        if [[ ${cur} == * ]]; then
-            if [[ ${#COMP_WORDS[@]} -gt 2 ]]; then
-                return 0
-            else
-                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
-                return 0
-            fi
-        fi
+    if [[ ${cur} == -* ]]; then
+        opts=$(heat --help | grep -A100 "^Options" | sed -r "s/^[[:space:]]*-[[:alpha:]]([[:space:]][[:alpha:]_]*,|,)[[:space:]]//" | cut -d "=" -f1 | grep "^--" | awk '{print $1}')
+        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+        return 0
+    fi
+
+    if [[ ${#COMP_WORDS[@]} -gt 2 ]]; then
+        return 0
+    else
+        cmds=$(heat help  | awk '{print $1}' | egrep -v "^(Usage|Commands|$)")
+        COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) )
+        return 0
+    fi
 }
 complete -F _heat heat