From 526d311458f2531ca8c610a46b3447cecc423dbf Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sat, 23 Nov 2024 21:03:29 +0000 Subject: [PATCH] feat: only block cask install on Linux --- Library/Homebrew/cask/installer.rb | 9 ++++++++ Library/Homebrew/extend/os/cask/installer.rb | 4 ++++ .../extend/os/linux/cask/installer.rb | 23 +++++++++++++++++++ .../Homebrew/extend/os/linux/cli/parser.rb | 10 -------- Library/Homebrew/test/cli/parser_spec.rb | 18 +-------------- 5 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 Library/Homebrew/extend/os/cask/installer.rb create mode 100644 Library/Homebrew/extend/os/linux/cask/installer.rb diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 0874fceb32a4a..a0cdf8b74a644 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -280,11 +280,18 @@ def install_artifacts(predecessor: nil) end end + sig { void } def check_requirements + check_stanza_os_requirements check_macos_requirements check_arch_requirements end + sig { void } + def check_stanza_os_requirements + nil + end + def check_macos_requirements return unless @cask.depends_on.macos return if @cask.depends_on.macos.satisfied? @@ -710,3 +717,5 @@ def load_cask_from_source_api! end end end + +require "extend/os/cask/installer" diff --git a/Library/Homebrew/extend/os/cask/installer.rb b/Library/Homebrew/extend/os/cask/installer.rb new file mode 100644 index 0000000000000..a7a6e0c277d9e --- /dev/null +++ b/Library/Homebrew/extend/os/cask/installer.rb @@ -0,0 +1,4 @@ +# typed: strict +# frozen_string_literal: true + +require "extend/os/linux/cask/installer" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/cask/installer.rb b/Library/Homebrew/extend/os/linux/cask/installer.rb new file mode 100644 index 0000000000000..536a08b1f5590 --- /dev/null +++ b/Library/Homebrew/extend/os/linux/cask/installer.rb @@ -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) diff --git a/Library/Homebrew/extend/os/linux/cli/parser.rb b/Library/Homebrew/extend/os/linux/cli/parser.rb index e5fd59e146cb9..50e50ff3b42fe 100644 --- a/Library/Homebrew/extend/os/linux/cli/parser.rb +++ b/Library/Homebrew/extend/os/linux/cli/parser.rb @@ -13,16 +13,6 @@ module Parser def set_default_options args["formula?"] = true if args.respond_to?(:formula?) end - - sig { void } - def validate_options - return unless args.respond_to?(:cask?) - return unless 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 diff --git a/Library/Homebrew/test/cli/parser_spec.rb b/Library/Homebrew/test/cli/parser_spec.rb index fec9fa061def3..941e7d45bfcbf 100644 --- a/Library/Homebrew/test/cli/parser_spec.rb +++ b/Library/Homebrew/test/cli/parser_spec.rb @@ -574,13 +574,6 @@ 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` # commands for formulae and casks on Linux. it "succeeds for developer commands" do @@ -599,18 +592,9 @@ 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 + .to raise_exception Homebrew::CLI::OptionConflictError end end end