[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.90-63-geab195c
Ville Skyttä
ville.skytta at iki.fi
Fri Nov 25 06:46:16 UTC 2011
The following commit has been merged in the master branch:
commit 3af9222e964739c3ca954bc1b966dc5628160457
Author: Ville Skyttä <ville.skytta at iki.fi>
Date: Thu Nov 24 23:26:52 2011 +0200
_parse_help, _parse_usage: If first arg is "-", read from stdin.
diff --git a/bash_completion b/bash_completion
index ac5842a..9bd43bd 100644
--- a/bash_completion
+++ b/bash_completion
@@ -735,14 +735,15 @@ __parse_options()
}
# Parse GNU style help output of the given command.
-# @param $1 command
+# @param $1 command; if "-", read from stdin and ignore rest of args
# @param $2 command options (default: --help)
#
_parse_help()
{
eval local cmd=$1
local line
- "$cmd" ${2:---help} 2>&1 | while read -r line; do
+ { case $cmd in -) cat ;; *) "$cmd" ${2:---help} 2>&1 ;; esac } \
+ | while read -r line; do
[[ $line == *([ $'\t'])-* ]] || continue
# transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc
@@ -756,14 +757,15 @@ _parse_help()
}
# Parse BSD style usage output (options in brackets) of the given command.
-# @param $1 command
+# @param $1 command; if "-", read from stdin and ignore rest of args
# @param $2 command options (default: --usage)
#
_parse_usage()
{
eval local cmd=$1
local line match option i char
- "$cmd" ${2:---usage} 2>&1 | while read -r line; do
+ { case $cmd in -) cat ;; *) "$cmd" ${2:---usage} 2>&1 ;; esac } \
+ | while read -r line; do
while [[ $line =~ \[[[:space:]]*(-[^]]+)[[:space:]]*\] ]]; do
match=${BASH_REMATCH[0]}
diff --git a/test/unit/_parse_help.exp b/test/unit/_parse_help.exp
index a6d58d5..43c5dc2 100644
--- a/test/unit/_parse_help.exp
+++ b/test/unit/_parse_help.exp
@@ -7,6 +7,7 @@ proc setup {} {
proc teardown {} {
assert_env_unmodified {
/declare -f fn/d
+ /PIPESTATUS=/d
}
}
@@ -129,5 +130,9 @@ set cmd {fn() { printf '%s\n' "-f or --foo"; }; _parse_help fn}
assert_bash_list "--foo" $cmd "-f or --foo"
sync_after_int
+set cmd { printf '%s\n' "-f or --foo" | _parse_help - }
+assert_bash_list "--foo" $cmd "from stdin"
+sync_after_int
+
teardown
diff --git a/test/unit/_parse_usage.exp b/test/unit/_parse_usage.exp
index 0069848..5a40b1f 100644
--- a/test/unit/_parse_usage.exp
+++ b/test/unit/_parse_usage.exp
@@ -5,6 +5,7 @@ proc setup {} {
proc teardown {} {
assert_env_unmodified {
/declare -f fn/d
+ /PIPESTATUS=/d
}
}
@@ -55,5 +56,9 @@ set cmd {fn() { printf '%s\n' "----\n---foo\n----- bar"; }; _parse_usage fn}
assert_bash_list "" $cmd "many dashes"
sync_after_int
+set cmd { printf '%s\n' "[-duh]" | _parse_usage - }
+assert_bash_list "-d -u -h" $cmd "from stdin"
+sync_after_int
+
teardown
--
bash-completion
More information about the Bash-completion-commits
mailing list