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
|
end
|
||||||
|
|
||||||
def respond_to_missing?(method_name, *)
|
def respond_to_missing?(method_name, *)
|
||||||
!frozen? || @table.key?(method_name)
|
@table.key?(method_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method_name, *args)
|
def method_missing(method_name, *args)
|
||||||
@ -152,5 +152,3 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "extend/os/args"
|
|
||||||
|
|||||||
@ -329,8 +329,11 @@ module Homebrew
|
|||||||
remaining + non_options
|
remaining + non_options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set_default_options
|
||||||
|
|
||||||
unless ignore_invalid_options
|
unless ignore_invalid_options
|
||||||
check_constraint_violations
|
check_constraint_violations
|
||||||
|
validate_options
|
||||||
check_named_args(named_args)
|
check_named_args(named_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -341,18 +344,16 @@ module Homebrew
|
|||||||
|
|
||||||
@args_parsed = true
|
@args_parsed = true
|
||||||
|
|
||||||
unless ignore_invalid_options
|
if !ignore_invalid_options && @args.help?
|
||||||
if @args.help?
|
puts generate_help_text
|
||||||
puts generate_help_text
|
exit
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
validate_options
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@args
|
@args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_default_options; end
|
||||||
|
|
||||||
def validate_options; end
|
def validate_options; end
|
||||||
|
|
||||||
def generate_help_text
|
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 Homebrew
|
||||||
module CLI
|
module CLI
|
||||||
class Parser
|
class Parser
|
||||||
|
undef set_default_options
|
||||||
undef validate_options
|
undef validate_options
|
||||||
|
|
||||||
|
def set_default_options
|
||||||
|
@args["formula?"] = true if @args.respond_to?(:formula?)
|
||||||
|
end
|
||||||
|
|
||||||
def validate_options
|
def validate_options
|
||||||
return unless @args.respond_to?(:cask?)
|
return unless @args.respond_to?(:cask?)
|
||||||
return unless @args.cask?
|
return unless @args.cask?
|
||||||
|
|
||||||
msg = "Casks are not supported on Linux"
|
raise UsageError, "Casks are not supported on Linux"
|
||||||
raise UsageError, msg unless Homebrew::EnvConfig.developer?
|
|
||||||
|
|
||||||
opoo msg unless @args.quiet?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -67,7 +67,7 @@ describe Homebrew::CLI::NamedArgs do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#to_formulae_and_casks" do
|
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_formula_loader foo, call_original: true
|
||||||
stub_cask_loader baz, 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)
|
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaOrCaskUnavailableError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error when formula is absent and cask is available on linux", :needs_linux do
|
it "returns formula when formula is present and cask is unreadable", :needs_macos 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
|
|
||||||
stub_formula_loader foo
|
stub_formula_loader foo
|
||||||
setup_unredable_cask "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
|
expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load cask: foo/).to_stderr
|
||||||
end
|
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"
|
setup_unredable_formula "foo"
|
||||||
stub_cask_loader foo_cask
|
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
|
expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load formula: foo/).to_stderr
|
||||||
end
|
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"
|
setup_unredable_cask "foo"
|
||||||
|
|
||||||
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(Cask::CaskUnreadableError)
|
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(Cask::CaskUnreadableError)
|
||||||
@ -162,7 +156,7 @@ describe Homebrew::CLI::NamedArgs do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#to_resolved_formulae_to_casks" do
|
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).and_call_original
|
||||||
allow(Formulary).to receive(:resolve).with("foo", any_args).and_return foo
|
allow(Formulary).to receive(:resolve).with("foo", any_args).and_return foo
|
||||||
stub_cask_loader baz, call_original: true
|
stub_cask_loader baz, call_original: true
|
||||||
@ -251,7 +245,7 @@ describe Homebrew::CLI::NamedArgs do
|
|||||||
(HOMEBREW_CELLAR/"foo/1.0").mkpath
|
(HOMEBREW_CELLAR/"foo/1.0").mkpath
|
||||||
end
|
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
|
stub_cask_loader baz, call_original: true
|
||||||
|
|
||||||
kegs, casks = described_class.new("foo", "baz").to_kegs_to_casks
|
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
|
allow(Cask::CaskLoader).to receive(:path).and_call_original
|
||||||
end
|
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(Formulary).to receive(:path).with("foo").and_return(formula_path)
|
||||||
expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_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]
|
.to eq [Tap.fetch("homebrew/core").path, formula_path, cask_path, existing_path]
|
||||||
end
|
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(Formulary).to receive(:path).with("foo").and_return(formula_path)
|
||||||
expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_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")]
|
expect(described_class.new("foo", "baz").to_paths(only: :cask)).to eq [cask_path, Cask::CaskLoader.path("baz")]
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "#to_taps" do
|
describe "#to_taps" do
|
||||||
|
|||||||
@ -570,12 +570,24 @@ describe Homebrew::CLI::Parser do
|
|||||||
end
|
end
|
||||||
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/
|
expect { parser.parse(["--cask"]) }.to raise_error UsageError, /Casks are not supported on Linux/
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "only warns developers", :dev_on_linux do
|
describe "--formula on linux", :needs_linux do
|
||||||
expect { parser.parse(["--cask"]) }.not_to raise_error
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -180,10 +180,6 @@ RSpec.configure do |config|
|
|||||||
skip "Unzip is not installed." unless which("unzip")
|
skip "Unzip is not installed." unless which("unzip")
|
||||||
end
|
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|
|
config.around do |example|
|
||||||
def find_files
|
def find_files
|
||||||
return [] unless File.exist?(TEST_TMPDIR)
|
return [] unless File.exist?(TEST_TMPDIR)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user