diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 64e8d4eb49..01215dd20a 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -152,5 +152,3 @@ module Homebrew end end end - -require "extend/os/args" diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 94571c54d5..897d56449d 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -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 diff --git a/Library/Homebrew/extend/os/args.rb b/Library/Homebrew/extend/os/args.rb deleted file mode 100644 index 2614878f98..0000000000 --- a/Library/Homebrew/extend/os/args.rb +++ /dev/null @@ -1,4 +0,0 @@ -# typed: true -# frozen_string_literal: true - -require "extend/os/linux/args" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/args.rb b/Library/Homebrew/extend/os/linux/args.rb deleted file mode 100644 index cb1835d849..0000000000 --- a/Library/Homebrew/extend/os/linux/args.rb +++ /dev/null @@ -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 diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb index c056ad8fa0..0c55c5862f 100644 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ b/Library/Homebrew/extend/os/linux/parser.rb @@ -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 diff --git a/Library/Homebrew/test/cli/named_args_spec.rb b/Library/Homebrew/test/cli/named_args_spec.rb index 6b2e8d2418..00b55fafc1 100644 --- a/Library/Homebrew/test/cli/named_args_spec.rb +++ b/Library/Homebrew/test/cli/named_args_spec.rb @@ -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) diff --git a/Library/Homebrew/test/cli/parser_spec.rb b/Library/Homebrew/test/cli/parser_spec.rb index 408295d91c..ce670b2f25 100644 --- a/Library/Homebrew/test/cli/parser_spec.rb +++ b/Library/Homebrew/test/cli/parser_spec.rb @@ -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 diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 437fb204ff..a9f9e5a22e 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -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)