Skip to content
Snippets Groups Projects
Commit 90e830c1 authored by EricFromCanada's avatar EricFromCanada
Browse files

cmd: add raises for invalid input

parent 2f7c3afe
No related branches found
No related tags found
No related merge requests found
...@@ -78,9 +78,12 @@ module Homebrew ...@@ -78,9 +78,12 @@ module Homebrew
if args.json if args.json
raise UsageError, "Invalid JSON version: #{args.json}" unless ["v1", true].include? 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 print_json
elsif args.github? 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) }) exec_browser(*Homebrew.args.formulae.map { |f| github_info(f) })
else else
print_info print_info
......
...@@ -23,6 +23,8 @@ module Homebrew ...@@ -23,6 +23,8 @@ module Homebrew
def postinstall def postinstall
postinstall_args.parse postinstall_args.parse
raise KegUnspecifiedError if args.remaining.empty?
ARGV.resolved_formulae.each do |f| ARGV.resolved_formulae.each do |f|
ohai "Postinstalling #{f}" ohai "Postinstalling #{f}"
fi = FormulaInstaller.new(f) fi = FormulaInstaller.new(f)
......
...@@ -47,6 +47,8 @@ module Homebrew ...@@ -47,6 +47,8 @@ module Homebrew
def reinstall def reinstall
reinstall_args.parse reinstall_args.parse
raise FormulaUnspecifiedError if args.remaining.empty?
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
Install.perform_preinstall_checks Install.perform_preinstall_checks
......
...@@ -14,46 +14,32 @@ module Homebrew ...@@ -14,46 +14,32 @@ module Homebrew
Symlink all of the specified <version> of <formula>'s installation into Homebrew's prefix. Symlink all of the specified <version> of <formula>'s installation into Homebrew's prefix.
EOS EOS
switch_option :verbose switch :verbose
switch_option :debug switch :debug
end end
end end
def switch def switch
switch_args.parse switch_args.parse
name = args.remaining.first
usage = "Usage: brew switch <formula> <version>"
unless name raise FormulaUnspecifiedError if args.remaining.empty?
onoe usage
exit 1
end
name = args.remaining.first
rack = Formulary.to_rack(name) rack = Formulary.to_rack(name)
unless rack.directory? odie "#{name} not found in the Cellar." unless rack.directory?
onoe "#{name} not found in the Cellar."
exit 2
end
versions = rack.subdirs versions = rack.subdirs
.map { |d| Keg.new(d).version } .map { |d| Keg.new(d).version }
.sort .sort
.join(", ") .join(", ")
version = args.remaining.second version = args.remaining.second
raise UsageError, "Specify one of #{name}'s installed versions: #{versions}" unless version
if !version || args.remaining.length > 2 odie <<~EOS unless (rack/version).directory?
onoe usage #{name} does not have a version \"#{version}\" in the Cellar.
puts "#{name} installed versions: #{versions}" #{name}'s installed versions: #{versions}
exit 1 EOS
end
unless (rack/version).directory?
onoe "#{name} does not have a version \"#{version}\" in the Cellar."
puts "#{name} installed versions: #{versions}"
exit 3
end
# Unlink all existing versions # Unlink all existing versions
rack.subdirs.each do |v| rack.subdirs.each do |v|
......
...@@ -86,6 +86,7 @@ module Homebrew ...@@ -86,6 +86,7 @@ module Homebrew
bottle_args.parse bottle_args.parse
return merge if args.merge? return merge if args.merge?
raise KegUnspecifiedError if args.remaining.empty?
ensure_relocation_formulae_installed! unless args.skip_relocation? ensure_relocation_formulae_installed! unless args.skip_relocation?
ARGV.resolved_formulae.each do |f| ARGV.resolved_formulae.each do |f|
...@@ -426,6 +427,7 @@ module Homebrew ...@@ -426,6 +427,7 @@ module Homebrew
def merge def merge
write = args.write? 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| bottles_hash = ARGV.named.reduce({}) do |hash, json_file|
hash.deep_merge(JSON.parse(IO.read(json_file))) hash.deep_merge(JSON.parse(IO.read(json_file)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment