[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 96c641630923e8db735316e5a7f4bef8741cadc2

Ville Skyttä ville.skytta at iki.fi
Sun Oct 10 21:40:17 UTC 2010


The following commit has been merged in the master branch:
commit 95399f638cc95dc262a94d845569a12a6a219a7a
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Mon Oct 11 00:01:51 2010 +0300

    Fix false posives for non-option words in _parse_help (Alioth: #312750, Stephen Gildea).

diff --git a/CHANGES b/CHANGES
index a127231..de2695a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -46,6 +46,9 @@ bash-completion (2.x)
   * Add *.part (partially downloaded) to mplayer and xine-based player
     completions (Alioth: #312657).
 
+  [ Stephen Gildea ]
+  * Fix false posives for non-option words in _parse_help (Alioth: #312750).
+
  -- David Paleino <d.paleino at gmail.com>  Wed, 16 Jun 2010 17:53:22 +0200
 
 bash-completion (1.2)
diff --git a/bash_completion b/bash_completion
index b2b3f1b..e411ca6 100644
--- a/bash_completion
+++ b/bash_completion
@@ -677,7 +677,7 @@ _split_longopt()
 #
 _parse_help() {
     $1 ${2:---help} 2>&1 | command grep -- "^[[:space:]]*-" | tr "," " " | \
-        awk '{print $1; if ($2 ~ /-.*/) { print $2 } }' | sed -e "s:=.*::g"
+        awk '{print $1; if ($2 ~ /^-.*/) { print $2 } }' | sed -e "s:=.*::g"
 }
 
 # This function completes on signal names
diff --git a/test/unit/_parse_help.exp b/test/unit/_parse_help.exp
new file mode 100644
index 0000000..c9ced6f
--- /dev/null
+++ b/test/unit/_parse_help.exp
@@ -0,0 +1,65 @@
+# By Stephen Gildea, October 2010. 
+
+proc setup {} {
+    save_env
+}
+
+proc teardown {} {
+    assert_env_unmodified {
+        /declare -f fn/d
+    }
+}
+
+setup
+
+
+set cmd {fn() { printf '%s\n' ""; }; _parse_help fn}
+assert_bash_list "" $cmd "empty"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "no dashes here"; }; _parse_help fn}
+assert_bash_list "" $cmd "no dashes"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "internal-dash"; }; _parse_help fn}
+assert_bash_list "" $cmd "internal dash 1"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "no -leading-dashes"; }; _parse_help fn}
+assert_bash_list "" $cmd "no leading dash"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "-one dash"; }; _parse_help fn}
+assert_bash_list "-one" $cmd "one dash"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' " -space dash"; }; _parse_help fn}
+assert_bash_list "-space" $cmd "one dash after space"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "-one -two dashes"; }; _parse_help fn}
+assert_bash_list "-one\n-two" $cmd "two dashes, space-separated"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "-one,-t dashes"; }; _parse_help fn}
+assert_bash_list "-one\n-t" $cmd "two dashes, comma-separated"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "-one dash-inside"; }; _parse_help fn}
+assert_bash_list "-one" $cmd "internal dash 2"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "--long-arg=value"; }; _parse_help fn}
+assert_bash_list "--long-arg" $cmd "value stripped"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "--long-arg=-value"; }; _parse_help fn}
+assert_bash_list "--long-arg" $cmd "value not seen as option"
+sync_after_int
+
+set cmd {fn() { printf '%s\n' "--long-arg=-value,--opt2=val"; }; _parse_help fn}
+assert_bash_list "--long-arg\n--opt2" $cmd "two options with values"
+sync_after_int
+
+
+teardown

-- 
bash-completion



More information about the Bash-completion-commits mailing list