Make :formula? the default on Linux

This makes :formula? the default whenever
defined throughout the codebase on Linux.
It also makes :cask? illegal for all Linux
users.
This commit is contained in:
apainintheneck 2022-12-03 22:08:01 -08:00
parent 93660d3de4
commit b7e28ef48f
8 changed files with 23 additions and 47 deletions

View File

@ -152,5 +152,3 @@ module Homebrew
end
end
end
require "extend/os/args"

View File

@ -329,8 +329,11 @@ module Homebrew
remaining + non_options
end
set_default_options
unless ignore_invalid_options
check_constraint_violations
validate_options
check_named_args(named_args)
end
@ -341,18 +344,16 @@ module Homebrew
@args_parsed = true
unless ignore_invalid_options
if @args.help?
if !ignore_invalid_options && @args.help?
puts generate_help_text
exit
end
validate_options
end
@args
end
def set_default_options; end
def validate_options; end
def generate_help_text

View File

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

View File

@ -1,17 +0,0 @@
# typed: true
# frozen_string_literal: true
module Homebrew
module CLI
class Args
undef only_formula_or_cask
def only_formula_or_cask
# Make formula the default on linux for non-developers
return :formula unless Homebrew::EnvConfig.developer?
return :formula if formula? && !cask?
return :cask if cask? && !formula?
end
end
end
end

View File

@ -4,16 +4,18 @@
module Homebrew
module CLI
class Parser
undef set_default_options
undef validate_options
def set_default_options
@args["formula?"] = true if @args.respond_to?(:formula?)
end
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?
raise UsageError, "Casks are not supported on Linux"
end
end
end

View File

@ -67,7 +67,7 @@ describe Homebrew::CLI::NamedArgs do
end
describe "#to_formulae_and_casks" do
it "returns formulae and casks", :dev_on_linux do
it "returns formulae and casks", :needs_macos do
stub_formula_loader foo, call_original: true
stub_cask_loader baz, call_original: true
@ -124,7 +124,7 @@ describe Homebrew::CLI::NamedArgs do
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnavailableError)
end
it "returns formula when formula is present and cask is unreadable", :dev_on_linux do
it "returns formula when formula is present and cask is unreadable", :needs_macos do
stub_formula_loader foo
setup_unredable_cask "foo"
@ -132,7 +132,7 @@ describe Homebrew::CLI::NamedArgs do
expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load cask: foo/).to_stderr
end
it "returns cask when formula is unreadable and cask is present", :dev_on_linux do
it "returns cask when formula is unreadable and cask is present", :needs_macos do
setup_unredable_formula "foo"
stub_cask_loader foo_cask
@ -140,7 +140,7 @@ describe Homebrew::CLI::NamedArgs do
expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load formula: foo/).to_stderr
end
it "raises an error when formula is absent and cask is unreadable", :dev_on_linux do
it "raises an error when formula is absent and cask is unreadable", :needs_macos do
setup_unredable_cask "foo"
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(Cask::CaskUnreadableError)
@ -162,7 +162,7 @@ describe Homebrew::CLI::NamedArgs do
end
describe "#to_resolved_formulae_to_casks" do
it "returns resolved formulae, as well as casks", :dev_on_linux do
it "returns resolved formulae, as well as casks", :needs_macos do
allow(Formulary).to receive(:resolve).and_call_original
allow(Formulary).to receive(:resolve).with("foo", any_args).and_return foo
stub_cask_loader baz, call_original: true
@ -251,7 +251,7 @@ describe Homebrew::CLI::NamedArgs do
(HOMEBREW_CELLAR/"foo/1.0").mkpath
end
it "returns kegs, as well as casks", :dev_on_linux do
it "returns kegs, as well as casks", :needs_macos do
stub_cask_loader baz, call_original: true
kegs, casks = described_class.new("foo", "baz").to_kegs_to_casks
@ -285,7 +285,7 @@ describe Homebrew::CLI::NamedArgs do
allow(Cask::CaskLoader).to receive(:path).and_call_original
end
it "returns taps, cask formula and existing paths", :dev_on_linux do
it "returns taps, cask formula and existing paths", :needs_macos do
expect(Formulary).to receive(:path).with("foo").and_return(formula_path)
expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path)
@ -293,7 +293,7 @@ describe Homebrew::CLI::NamedArgs do
.to eq [Tap.fetch("homebrew/core").path, formula_path, cask_path, existing_path]
end
it "returns both cask and formula paths if they exist", :dev_on_linux do
it "returns both cask and formula paths if they exist", :needs_macos do
expect(Formulary).to receive(:path).with("foo").and_return(formula_path)
expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path)

View File

@ -574,7 +574,7 @@ describe Homebrew::CLI::Parser do
expect { parser.parse(["--cask"]) }.to raise_error UsageError, /Casks are not supported on Linux/
end
it "only warns developers", :dev_on_linux do
it "only warns developers", :needs_macos do
expect { parser.parse(["--cask"]) }.not_to raise_error
end
end

View File

@ -180,10 +180,6 @@ RSpec.configure do |config|
skip "Unzip is not installed." unless which("unzip")
end
config.before(:each, :dev_on_linux) do
allow(Homebrew::EnvConfig).to receive(:developer?).and_return(true) if OS.linux?
end
config.around do |example|
def find_files
return [] unless File.exist?(TEST_TMPDIR)