diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 897d56449d..f2d58d1126 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -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 diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb index 0c55c5862f..0195c1f67b 100644 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ b/Library/Homebrew/extend/os/linux/parser.rb @@ -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 diff --git a/Library/Homebrew/test/cli/parser_spec.rb b/Library/Homebrew/test/cli/parser_spec.rb index b2983a09bb..51ab257815 100644 --- a/Library/Homebrew/test/cli/parser_spec.rb +++ b/Library/Homebrew/test/cli/parser_spec.rb @@ -564,14 +564,37 @@ 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 raise_error RuntimeError, "Invalid usage: Casks are not supported on Linux" 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 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