cmd: add raises for invalid input

This commit is contained in:
EricFromCanada 2019-12-13 15:44:28 -05:00
parent 2f7c3afeb8
commit 90e830c19e
5 changed files with 20 additions and 25 deletions

View File

@ -78,9 +78,12 @@ module Homebrew
if args.json
raise UsageError, "Invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
raise UsageError, "This command's option requires a formula argument" if ARGV.named.empty?
print_json
elsif args.github?
raise UsageError, "This command's option requires a formula argument" if ARGV.named.empty?
exec_browser(*Homebrew.args.formulae.map { |f| github_info(f) })
else
print_info

View File

@ -23,6 +23,8 @@ module Homebrew
def postinstall
postinstall_args.parse
raise KegUnspecifiedError if args.remaining.empty?
ARGV.resolved_formulae.each do |f|
ohai "Postinstalling #{f}"
fi = FormulaInstaller.new(f)

View File

@ -47,6 +47,8 @@ module Homebrew
def reinstall
reinstall_args.parse
raise FormulaUnspecifiedError if args.remaining.empty?
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
Install.perform_preinstall_checks

View File

@ -14,46 +14,32 @@ module Homebrew
Symlink all of the specified <version> of <formula>'s installation into Homebrew's prefix.
EOS
switch_option :verbose
switch_option :debug
switch :verbose
switch :debug
end
end
def switch
switch_args.parse
raise FormulaUnspecifiedError if args.remaining.empty?
name = args.remaining.first
usage = "Usage: brew switch <formula> <version>"
unless name
onoe usage
exit 1
end
rack = Formulary.to_rack(name)
unless rack.directory?
onoe "#{name} not found in the Cellar."
exit 2
end
odie "#{name} not found in the Cellar." unless rack.directory?
versions = rack.subdirs
.map { |d| Keg.new(d).version }
.sort
.join(", ")
version = args.remaining.second
raise UsageError, "Specify one of #{name}'s installed versions: #{versions}" unless version
if !version || args.remaining.length > 2
onoe usage
puts "#{name} installed versions: #{versions}"
exit 1
end
unless (rack/version).directory?
onoe "#{name} does not have a version \"#{version}\" in the Cellar."
puts "#{name} installed versions: #{versions}"
exit 3
end
odie <<~EOS unless (rack/version).directory?
#{name} does not have a version \"#{version}\" in the Cellar.
#{name}'s installed versions: #{versions}
EOS
# Unlink all existing versions
rack.subdirs.each do |v|

View File

@ -86,6 +86,7 @@ module Homebrew
bottle_args.parse
return merge if args.merge?
raise KegUnspecifiedError if args.remaining.empty?
ensure_relocation_formulae_installed! unless args.skip_relocation?
ARGV.resolved_formulae.each do |f|
@ -426,6 +427,7 @@ module Homebrew
def merge
write = args.write?
raise UsageError, "--merge requires a JSON file path argument" if ARGV.named.empty?
bottles_hash = ARGV.named.reduce({}) do |hash, json_file|
hash.deep_merge(JSON.parse(IO.read(json_file)))