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:
parent
93660d3de4
commit
b7e28ef48f
@ -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
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ describe Homebrew::CLI::NamedArgs do
|
|||||||
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnavailableError)
|
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnavailableError)
|
||||||
end
|
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
|
stub_formula_loader foo
|
||||||
setup_unredable_cask "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
|
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 +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
|
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 +162,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 +251,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 +285,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 +293,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)
|
||||||
|
|
||||||
|
|||||||
@ -574,7 +574,7 @@ describe Homebrew::CLI::Parser 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
|
||||||
|
|
||||||
it "only warns developers", :dev_on_linux do
|
it "only warns developers", :needs_macos do
|
||||||
expect { parser.parse(["--cask"]) }.not_to raise_error
|
expect { parser.parse(["--cask"]) }.not_to raise_error
|
||||||
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