diff options
| author | Martin Afanasjew | 2016-05-11 05:08:09 +0200 |
|---|---|---|
| committer | Martin Afanasjew | 2016-05-12 08:09:19 +0200 |
| commit | 1087df1016f65e3b1cef9a11597086e56674a369 (patch) | |
| tree | d3aa9c662f91f78b363909e97b8b8c563a33ccc6 /Library | |
| parent | 2e961dc9dee63f641f7f162fd7a2845c5fd092fe (diff) | |
| download | brew-1087df1016f65e3b1cef9a11597086e56674a369.tar.bz2 | |
ARGV: fix 'value' method, make it more predictable
The fix changes behavior in same cases, but those cases were all either
broken or showed unexpected behavior. The new behavior is very simple:
- If an argument starts with `--<option-name>=`, return whatever comes
after the equals sign.
Prior to this change, `ARGV.value` showed some unexpected behavior:
- `ARGV.value("foo")` returned `nil` for `--foo=` because at least one
character needed to be present after the equals sign. (All other
option parser implementations I'm aware of allow for empty values.)
- `ARGV.value("bar")` returned `"baz"` for `--foo=--bar=baz` because the
regular expression was not anchored to the start of the argument.
- `ARGV.value("++")` raised an exception because the string wasn't
escaped for use in the regular expression. (An unlikely corner case.)
Closes #231.
Signed-off-by: Martin Afanasjew <martin@afanasjew.de>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/extend/ARGV.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index bb26d453f..8f783aea1 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -87,9 +87,10 @@ module HomebrewArgvExtension at(@n+1) || raise(UsageError) end - def value(arg) - arg = find { |o| o =~ /--#{arg}=(.+)/ } - $1 if arg + def value(name) + arg_prefix = "--#{name}=" + flag_with_value = find { |arg| arg.start_with?(arg_prefix) } + flag_with_value.strip_prefix(arg_prefix) if flag_with_value end def force? |
