Merge pull request #14315 from apainintheneck/better-error-cask-on-linux
cli/parser: Better error message for cask on linux
This commit is contained in:
commit
2e0b18f762
@ -332,8 +332,8 @@ module Homebrew
|
||||
set_default_options
|
||||
|
||||
unless ignore_invalid_options
|
||||
check_constraint_violations
|
||||
validate_options
|
||||
check_constraint_violations
|
||||
check_named_args(named_args)
|
||||
end
|
||||
|
||||
|
||||
@ -297,7 +297,12 @@ module Homebrew
|
||||
return if name.include?("/")
|
||||
|
||||
require "search"
|
||||
ohai "Searching for similarly named formulae and casks..."
|
||||
|
||||
package_types = []
|
||||
package_types << "formulae" unless args.cask?
|
||||
package_types << "casks" unless args.formula?
|
||||
|
||||
ohai "Searching for similarly named #{package_types.join(" and ")}..."
|
||||
|
||||
# Don't treat formula/cask name as a regex
|
||||
query = string_or_regex = name
|
||||
@ -324,6 +329,6 @@ module Homebrew
|
||||
end
|
||||
return if all_formulae.any? || all_casks.any?
|
||||
|
||||
odie "No formulae or casks found for #{name}."
|
||||
odie "No #{package_types.join(" or ")} found for #{name}."
|
||||
end
|
||||
end
|
||||
|
||||
@ -15,7 +15,9 @@ module Homebrew
|
||||
return unless @args.respond_to?(:cask?)
|
||||
return unless @args.cask?
|
||||
|
||||
raise UsageError, "Casks are not supported on Linux"
|
||||
# NOTE: We don't raise an error here because we don't want
|
||||
# to print the help page or a stack trace.
|
||||
odie "Invalid `--cask` usage: Casks do not work on Linux"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -564,14 +564,43 @@ describe Homebrew::CLI::Parser do
|
||||
end
|
||||
|
||||
describe "--cask on linux", :needs_linux do
|
||||
subject(:parser) do
|
||||
described_class.new do
|
||||
switch "--cask"
|
||||
context "without --formula switch" do
|
||||
subject(:parser) do
|
||||
described_class.new do
|
||||
switch "--cask"
|
||||
end
|
||||
end
|
||||
|
||||
it "throws an error when defined" do
|
||||
expect { parser.parse(["--cask"]) }
|
||||
.to output("Error: Invalid `--cask` usage: Casks do not work on Linux\n").to_stderr
|
||||
.and not_to_output.to_stdout
|
||||
.and raise_exception SystemExit
|
||||
end
|
||||
end
|
||||
|
||||
it "throws an error when defined" do
|
||||
expect { parser.parse(["--cask"]) }.to raise_error UsageError, /Casks are not supported on Linux/
|
||||
context "with conflicting --formula switch" do
|
||||
subject(:parser) do
|
||||
described_class.new do
|
||||
switch "--cask"
|
||||
switch "--formula"
|
||||
conflicts "--cask", "--formula"
|
||||
end
|
||||
end
|
||||
|
||||
it "throws an error when --cask defined" do
|
||||
expect { parser.parse(["--cask"]) }
|
||||
.to output("Error: Invalid `--cask` usage: Casks do not work on Linux\n").to_stderr
|
||||
.and not_to_output.to_stdout
|
||||
.and raise_exception SystemExit
|
||||
end
|
||||
|
||||
it "throws an error when both defined" do
|
||||
expect { parser.parse(["--cask", "--formula"]) }
|
||||
.to output("Error: Invalid `--cask` usage: Casks do not work on Linux\n").to_stderr
|
||||
.and not_to_output.to_stdout
|
||||
.and raise_exception SystemExit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user