Better errors if missing keg or formula arguments
This commit is contained in:
parent
03ca3e24d0
commit
8081a95c4a
@ -21,6 +21,10 @@
|
|||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
|
class UsageError <RuntimeError; end
|
||||||
|
class FormulaUnspecifiedError <UsageError; end
|
||||||
|
class KegUnspecifiedError <UsageError; end
|
||||||
|
|
||||||
module HomebrewArgvExtension
|
module HomebrewArgvExtension
|
||||||
def named
|
def named
|
||||||
@named ||= reject{|arg| arg[0..0] == '-'}
|
@named ||= reject{|arg| arg[0..0] == '-'}
|
||||||
@ -31,7 +35,7 @@ module HomebrewArgvExtension
|
|||||||
def formulae
|
def formulae
|
||||||
require 'formula'
|
require 'formula'
|
||||||
@formulae ||= downcased_unique_named.collect {|name| Formula.factory name}
|
@formulae ||= downcased_unique_named.collect {|name| Formula.factory name}
|
||||||
raise UsageError if @formulae.empty?
|
raise FormulaUnspecifiedError if @formulae.empty?
|
||||||
@formulae
|
@formulae
|
||||||
end
|
end
|
||||||
def kegs
|
def kegs
|
||||||
@ -42,7 +46,7 @@ module HomebrewArgvExtension
|
|||||||
raise "#{name} has multiple installed versions" if d.children.length > 1
|
raise "#{name} has multiple installed versions" if d.children.length > 1
|
||||||
Keg.new d.children[0]
|
Keg.new d.children[0]
|
||||||
end
|
end
|
||||||
raise UsageError if @kegs.empty?
|
raise KegUnspecifiedError if @kegs.empty?
|
||||||
@kegs
|
@kegs
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -113,5 +117,3 @@ To visit the Homebrew homepage type:
|
|||||||
@downcased_unique_named ||= named.collect{|arg| arg.downcase}.uniq
|
@downcased_unique_named ||= named.collect{|arg| arg.downcase}.uniq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class UsageError <RuntimeError; end
|
|
||||||
|
@ -407,10 +407,9 @@ class BeerTasting <Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_ARGV
|
def test_ARGV
|
||||||
assert_raises(UsageError) { ARGV.named }
|
assert_raises(FormulaUnspecifiedError) { ARGV.formulae }
|
||||||
assert_raises(UsageError) { ARGV.formulae }
|
assert_raises(KegUnspecifiedError) { ARGV.kegs }
|
||||||
assert_raises(UsageError) { ARGV.kegs }
|
assert ARGV.named.empty?
|
||||||
assert ARGV.named_empty?
|
|
||||||
|
|
||||||
(HOMEBREW_CELLAR+'mxcl'+'10.0').mkpath
|
(HOMEBREW_CELLAR+'mxcl'+'10.0').mkpath
|
||||||
|
|
||||||
|
6
bin/brew
6
bin/brew
@ -224,6 +224,12 @@ begin
|
|||||||
puts ARGV.usage
|
puts ARGV.usage
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue FormulaUnspecifiedError
|
||||||
|
puts "This command requires a formula argument"
|
||||||
|
exit 1
|
||||||
|
rescue KegUnspecifiedError
|
||||||
|
puts "This command requires a keg argument"
|
||||||
|
exit 1
|
||||||
rescue UsageError
|
rescue UsageError
|
||||||
onoe "Invalid usage"
|
onoe "Invalid usage"
|
||||||
puts ARGV.usage
|
puts ARGV.usage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user