Skip to content

Commit

Permalink
feat: only block cask install on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Dec 4, 2024
1 parent b93c179 commit 526d311
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
9 changes: 9 additions & 0 deletions Library/Homebrew/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -710,3 +717,5 @@ def load_cask_from_source_api!
end
end
end

require "extend/os/cask/installer"
4 changes: 4 additions & 0 deletions Library/Homebrew/extend/os/cask/installer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# typed: strict
# frozen_string_literal: true

require "extend/os/linux/cask/installer" if OS.linux?
23 changes: 23 additions & 0 deletions Library/Homebrew/extend/os/linux/cask/installer.rb
Original file line number Diff line number Diff line change
@@ -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."

Check warning on line 16 in Library/Homebrew/extend/os/linux/cask/installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/cask/installer.rb#L16

Added line #L16 was not covered by tests
end
end
end
end
end

Cask::Installer.prepend(OS::Linux::Cask::Installer)
10 changes: 0 additions & 10 deletions Library/Homebrew/extend/os/linux/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 1 addition & 17 deletions Library/Homebrew/test/cli/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 526d311

Please sign in to comment.