Warn linux users about using --cask

This commit is contained in:
apainintheneck 2022-09-28 21:57:13 -07:00
parent 206d9932d2
commit 020c50e588
6 changed files with 55 additions and 5 deletions

View File

@ -341,14 +341,20 @@ module Homebrew
@args_parsed = true
if !ignore_invalid_options && @args.help?
unless ignore_invalid_options
if @args.help?
puts generate_help_text
exit
end
validate_options
end
@args
end
def validate_options; end
def generate_help_text
Formatter.format_help_text(@parser.to_s, width: COMMAND_DESC_WIDTH)
.gsub(/\n.*?@@HIDDEN@@.*?(?=\n)/, "")
@ -701,3 +707,5 @@ module Homebrew
end
end
end
require "extend/os/parser"

View File

@ -0,0 +1,20 @@
# typed: false
# frozen_string_literal: true
module Homebrew
module CLI
class Parser
undef validate_options
def validate_options
return unless @args.respond_to?(:cask?)
return unless @args.cask?
msg = "Casks are not supported on Linux"
raise UsageError, msg unless Homebrew::EnvConfig.developer?
opoo msg unless @args.quiet?
end
end
end
end

View File

@ -0,0 +1,4 @@
# typed: false
# frozen_string_literal: true
require "extend/os/linux/parser" if OS.linux?

View File

@ -562,4 +562,22 @@ describe Homebrew::CLI::Parser do
expect { parser.parse(["--not-a-command"]) }.to raise_error(OptionParser::InvalidOption, /--not-a-command/)
end
end
describe "--cask on linux", :needs_linux do
subject(:parser) do
described_class.new do
switch "--cask"
end
end
it "throws an error for normal users" do
allow(Homebrew::EnvConfig).to receive(:developer?).and_return(false)
expect { parser.parse(["--cask"]) }.to raise_error UsageError, /Casks are not supported on Linux/
end
it "only warns developers" do
allow(Homebrew::EnvConfig).to receive(:developer?).and_return(true)
expect { parser.parse(["--cask"]) }.not_to raise_error
end
end
end

View File

@ -17,7 +17,7 @@ describe "brew --cache" do
.and be_a_success
end
it "prints the cache files for a given Cask", :integration_test do
it "prints the cache files for a given Cask", :integration_test, :needs_macos do
expect { brew "--cache", cask_path("local-caffeine") }
.to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}o).to_stdout
.and output(/Treating #{Regexp.escape(cask_path("local-caffeine"))} as a cask/).to_stderr

View File

@ -34,7 +34,7 @@ describe "brew home" do
.and be_a_success
end
it "opens the homepage for a given Cask", :integration_test do
it "opens the homepage for a given Cask", :integration_test, :needs_macos do
expect { brew "home", local_caffeine_path, "HOMEBREW_BROWSER" => "echo" }
.to output(/#{local_caffeine_homepage}/).to_stdout
.and output(/Treating #{Regexp.escape(local_caffeine_path)} as a cask/).to_stderr