feat: only block cask install on Linux

This commit is contained in:
Sean Molenaar 2024-11-23 21:03:29 +00:00 committed by Sean Molenaar
parent a86c7c1d7a
commit cb23433612
No known key found for this signature in database
5 changed files with 47 additions and 27 deletions

View File

@ -280,11 +280,18 @@ on_request: true)
end end
end end
sig { void }
def check_requirements def check_requirements
check_stanza_os_requirements
check_macos_requirements check_macos_requirements
check_arch_requirements check_arch_requirements
end end
sig { void }
def check_stanza_os_requirements
nil
end
def check_macos_requirements def check_macos_requirements
return unless @cask.depends_on.macos return unless @cask.depends_on.macos
return if @cask.depends_on.macos.satisfied? return if @cask.depends_on.macos.satisfied?
@ -710,3 +717,5 @@ on_request: true)
end end
end end
end end
require "extend/os/cask/installer"

View File

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

View File

@ -0,0 +1,23 @@
# typed: strict
# frozen_string_literal: true
module OS
module Linux
module Cask
module Installer
private
extend T::Helpers
requires_ancestor { ::Cask::Installer }
sig { void }
def check_stanza_os_requirements
raise ::Cask::CaskError, "macOS is required for this software."
end
end
end
end
end
Cask::Installer.prepend(OS::Linux::Cask::Installer)

View File

@ -11,18 +11,10 @@ module OS
sig { void } sig { void }
def set_default_options def set_default_options
return if args.only_formula_or_cask == :cask
args.set_arg(:formula?, true) args.set_arg(:formula?, true)
end end
sig { void }
def validate_options
return unless args.respond_to?(:cask?)
return unless T.unsafe(self).args.cask?
# 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
end end
end end

View File

@ -574,13 +574,6 @@ RSpec.describe Homebrew::CLI::Parser do
end end
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
# Developers want to be able to use `audit` and `bump` # Developers want to be able to use `audit` and `bump`
# commands for formulae and casks on Linux. # commands for formulae and casks on Linux.
it "succeeds for developer commands" do it "succeeds for developer commands" do
@ -599,18 +592,9 @@ RSpec.describe Homebrew::CLI::Parser do
end end
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 it "throws an error when both defined" do
expect { parser.parse(["--cask", "--formula"]) } expect { parser.parse(["--cask", "--formula"]) }
.to output("Error: Invalid `--cask` usage: Casks do not work on Linux\n").to_stderr .to raise_exception Homebrew::CLI::OptionConflictError
.and not_to_output.to_stdout
.and raise_exception SystemExit
end end
end end
end end
@ -629,5 +613,13 @@ RSpec.describe Homebrew::CLI::Parser do
args = parser.parse([]) args = parser.parse([])
expect(args.formula?).to be(true) expect(args.formula?).to be(true)
end end
it "does not set --formula to true when --cask" do
parser = described_class.new(Cmd) do
switch "--cask"
end
args = parser.parse([])
expect(args.respond_to?(:formula?)).to be(false)
end
end end
end end