Implement ARGV.named in terms of ARGV.options_only

This commit is contained in:
Jack Nagel 2014-08-28 22:11:08 -05:00
parent 7a5e4f5cca
commit e18da89f3c
2 changed files with 9 additions and 4 deletions

View File

@ -1,10 +1,10 @@
module HomebrewArgvExtension
def named
@named ||= reject{|arg| arg[0..0] == '-'}
@named ||= self - options_only
end
def options_only
select {|arg| arg[0..0] == '-'}
select { |arg| arg.start_with?("-") }
end
def formulae

View File

@ -21,8 +21,13 @@ class ArgvExtensionTests < Homebrew::TestCase
end
def test_argv_named
@argv << 'mxcl' << '--debug' << '-v'
assert_equal 1, @argv.named.length
@argv << "foo" << "--debug" << "-v"
assert_equal %w[foo], @argv.named
end
def test_options_only
@argv << "--foo" << "-vds" << "a" << "b" << "cdefg"
assert_equal %w[--foo -vds], @argv.options_only
end
def test_empty_argv