cli/parser: Better error message for cask on linux
1. Validate options before constraint violations. This allows us to error out when --cask is passed on Linux before getting a constraint violation when --cask and --formula are set. 2. Skip printing the help page when --cask is passed on Linux.
This commit is contained in:
parent
e76c55e184
commit
a8384c0ce7
@ -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
|
||||
|
||||
|
@ -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 a UsageError here because
|
||||
# we don't want to print the help page.
|
||||
raise "Invalid usage: Casks are not supported on Linux"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -564,6 +564,7 @@ describe Homebrew::CLI::Parser do
|
||||
end
|
||||
|
||||
describe "--cask on linux", :needs_linux do
|
||||
context "without --formula switch" do
|
||||
subject(:parser) do
|
||||
described_class.new do
|
||||
switch "--cask"
|
||||
@ -571,7 +572,29 @@ describe Homebrew::CLI::Parser do
|
||||
end
|
||||
|
||||
it "throws an error when defined" do
|
||||
expect { parser.parse(["--cask"]) }.to raise_error UsageError, /Casks are not supported on Linux/
|
||||
expect { parser.parse(["--cask"]) }
|
||||
.to raise_error RuntimeError, "Invalid usage: Casks are not supported on Linux"
|
||||
end
|
||||
end
|
||||
|
||||
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 raise_error RuntimeError, "Invalid usage: Casks are not supported on Linux"
|
||||
end
|
||||
|
||||
it "throws an error when both defined" do
|
||||
expect { parser.parse(["--cask", "--formula"]) }
|
||||
.to raise_error RuntimeError, "Invalid usage: Casks are not supported on Linux"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user