Merge pull request #14206 from apainintheneck/make-formula-default-on-linux
Make :formula? the default on Linux
This commit is contained in:
commit
3070fd7fef
@ -135,7 +135,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def respond_to_missing?(method_name, *)
|
||||
!frozen? || @table.key?(method_name)
|
||||
@table.key?(method_name)
|
||||
end
|
||||
|
||||
def method_missing(method_name, *args)
|
||||
@ -152,5 +152,3 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require "extend/os/args"
|
||||
|
||||
@ -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?
|
||||
puts generate_help_text
|
||||
exit
|
||||
end
|
||||
|
||||
validate_options
|
||||
if !ignore_invalid_options && @args.help?
|
||||
puts generate_help_text
|
||||
exit
|
||||
end
|
||||
|
||||
@args
|
||||
end
|
||||
|
||||
def set_default_options; end
|
||||
|
||||
def validate_options; end
|
||||
|
||||
def generate_help_text
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "extend/os/linux/args" if OS.linux?
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -118,13 +118,7 @@ describe Homebrew::CLI::NamedArgs do
|
||||
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaOrCaskUnavailableError)
|
||||
end
|
||||
|
||||
it "raises an error when formula is absent and cask is available on linux", :needs_linux do
|
||||
stub_cask_loader foo_cask
|
||||
|
||||
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 +126,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 +134,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 +156,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 +245,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 +279,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 +287,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)
|
||||
|
||||
@ -311,12 +305,6 @@ describe Homebrew::CLI::NamedArgs do
|
||||
|
||||
expect(described_class.new("foo", "baz").to_paths(only: :cask)).to eq [cask_path, Cask::CaskLoader.path("baz")]
|
||||
end
|
||||
|
||||
it "returns only formulae by default on linux", :needs_linux do
|
||||
expect(Formulary).to receive(:path).with("foo").and_return(formula_path)
|
||||
|
||||
expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, Formulary.path("baz")]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_taps" do
|
||||
|
||||
@ -570,12 +570,24 @@ describe Homebrew::CLI::Parser do
|
||||
end
|
||||
end
|
||||
|
||||
it "throws an error by default" do
|
||||
it "throws an error when defined" do
|
||||
expect { parser.parse(["--cask"]) }.to raise_error UsageError, /Casks are not supported on Linux/
|
||||
end
|
||||
end
|
||||
|
||||
it "only warns developers", :dev_on_linux do
|
||||
expect { parser.parse(["--cask"]) }.not_to raise_error
|
||||
describe "--formula on linux", :needs_linux do
|
||||
it "doesn't set --formula when not defined" do
|
||||
parser = described_class.new
|
||||
args = parser.parse([])
|
||||
expect(args.respond_to?(:formula?)).to be(false)
|
||||
end
|
||||
|
||||
it "sets --formula to true when defined" do
|
||||
parser = described_class.new do
|
||||
switch "--formula"
|
||||
end
|
||||
args = parser.parse([])
|
||||
expect(args.formula?).to be(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user