From d50a8c4e412293138877d6c1026e7bc83647d1d6 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 2 Jan 2020 14:07:07 +0000 Subject: [PATCH] ARGV: delete/make private some more methods. --- Library/Homebrew/extend/ARGV.rb | 29 ++++++++--------------------- Library/Homebrew/test/ARGV_spec.rb | 14 +++++++------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index 2ea48357dd..575c5c62a4 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -6,10 +6,6 @@ module HomebrewArgvExtension self - options_only end - def options_only - select { |arg| arg.start_with?("-") } - end - def flags_only select { |arg| arg.start_with?("--") } end @@ -26,15 +22,6 @@ module HomebrewArgvExtension end.uniq(&:name) end - def resolved_formulae - odeprecated("ARGV#resolved_formulae", "Args#resolved_formulae") - require "formula" - # TODO: use @instance variable to ||= cache when moving to CLI::Parser - (downcased_unique_named - casks).map do |name| - Formulary.resolve(name, spec: spec(nil)) - end.uniq(&:name) - end - def casks # TODO: use @instance variable to ||= cache when moving to CLI::Parser downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX @@ -119,18 +106,10 @@ module HomebrewArgvExtension formulae.any? { |argv_f| argv_f.full_name == f.full_name } end - def flag?(flag) - options_only.include?(flag) || switch?(flag[2, 1]) - end - def force_bottle? include?("--force-bottle") end - def fetch_head? - include? "--fetch-HEAD" - end - def cc value "cc" end @@ -154,6 +133,14 @@ module HomebrewArgvExtension private + def options_only + select { |arg| arg.start_with?("-") } + end + + def flag?(flag) + options_only.include?(flag) || switch?(flag[2, 1]) + end + # e.g. `foo -ns -i --bar` has three switches: `n`, `s` and `i` def switch?(char) return false if char.length > 1 diff --git a/Library/Homebrew/test/ARGV_spec.rb b/Library/Homebrew/test/ARGV_spec.rb index b8ccd4d831..1fa852f60e 100644 --- a/Library/Homebrew/test/ARGV_spec.rb +++ b/Library/Homebrew/test/ARGV_spec.rb @@ -47,7 +47,7 @@ describe HomebrewArgvExtension do let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] } it "returns an array of option arguments" do - expect(subject.options_only).to eq ["--foo", "-vds"] + expect(subject.send("options_only")).to eq ["--foo", "-vds"] end end @@ -87,18 +87,18 @@ describe HomebrewArgvExtension do let(:argv) { ["--foo", "-bq", "--bar"] } it "returns true if the given string is a flag" do - expect(subject.flag?("--foo")).to eq true - expect(subject.flag?("--bar")).to eq true + expect(subject.send("flag?", "--foo")).to eq true + expect(subject.send("flag?", "--bar")).to eq true end it "returns true if there is a switch with the same initial character" do - expect(subject.flag?("--baz")).to eq true - expect(subject.flag?("--qux")).to eq true + expect(subject.send("flag?", "--baz")).to eq true + expect(subject.send("flag?", "--qux")).to eq true end it "returns false if there is no matching flag" do - expect(subject.flag?("--frotz")).to eq false - expect(subject.flag?("--debug")).to eq false + expect(subject.send("flag?", "--frotz")).to eq false + expect(subject.send("flag?", "--debug")).to eq false end end