ARGV: delete/make private some more methods.
This commit is contained in:
parent
c87416e525
commit
d50a8c4e41
@ -6,10 +6,6 @@ module HomebrewArgvExtension
|
|||||||
self - options_only
|
self - options_only
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_only
|
|
||||||
select { |arg| arg.start_with?("-") }
|
|
||||||
end
|
|
||||||
|
|
||||||
def flags_only
|
def flags_only
|
||||||
select { |arg| arg.start_with?("--") }
|
select { |arg| arg.start_with?("--") }
|
||||||
end
|
end
|
||||||
@ -26,15 +22,6 @@ module HomebrewArgvExtension
|
|||||||
end.uniq(&:name)
|
end.uniq(&:name)
|
||||||
end
|
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
|
def casks
|
||||||
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
# TODO: use @instance variable to ||= cache when moving to CLI::Parser
|
||||||
downcased_unique_named.grep HOMEBREW_CASK_TAP_CASK_REGEX
|
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 }
|
formulae.any? { |argv_f| argv_f.full_name == f.full_name }
|
||||||
end
|
end
|
||||||
|
|
||||||
def flag?(flag)
|
|
||||||
options_only.include?(flag) || switch?(flag[2, 1])
|
|
||||||
end
|
|
||||||
|
|
||||||
def force_bottle?
|
def force_bottle?
|
||||||
include?("--force-bottle")
|
include?("--force-bottle")
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_head?
|
|
||||||
include? "--fetch-HEAD"
|
|
||||||
end
|
|
||||||
|
|
||||||
def cc
|
def cc
|
||||||
value "cc"
|
value "cc"
|
||||||
end
|
end
|
||||||
@ -154,6 +133,14 @@ module HomebrewArgvExtension
|
|||||||
|
|
||||||
private
|
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`
|
# e.g. `foo -ns -i --bar` has three switches: `n`, `s` and `i`
|
||||||
def switch?(char)
|
def switch?(char)
|
||||||
return false if char.length > 1
|
return false if char.length > 1
|
||||||
|
|||||||
@ -47,7 +47,7 @@ describe HomebrewArgvExtension do
|
|||||||
let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] }
|
let(:argv) { ["--foo", "-vds", "a", "b", "cdefg"] }
|
||||||
|
|
||||||
it "returns an array of option arguments" do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -87,18 +87,18 @@ describe HomebrewArgvExtension do
|
|||||||
let(:argv) { ["--foo", "-bq", "--bar"] }
|
let(:argv) { ["--foo", "-bq", "--bar"] }
|
||||||
|
|
||||||
it "returns true if the given string is a flag" do
|
it "returns true if the given string is a flag" do
|
||||||
expect(subject.flag?("--foo")).to eq true
|
expect(subject.send("flag?", "--foo")).to eq true
|
||||||
expect(subject.flag?("--bar")).to eq true
|
expect(subject.send("flag?", "--bar")).to eq true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns true if there is a switch with the same initial character" do
|
it "returns true if there is a switch with the same initial character" do
|
||||||
expect(subject.flag?("--baz")).to eq true
|
expect(subject.send("flag?", "--baz")).to eq true
|
||||||
expect(subject.flag?("--qux")).to eq true
|
expect(subject.send("flag?", "--qux")).to eq true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if there is no matching flag" do
|
it "returns false if there is no matching flag" do
|
||||||
expect(subject.flag?("--frotz")).to eq false
|
expect(subject.send("flag?", "--frotz")).to eq false
|
||||||
expect(subject.flag?("--debug")).to eq false
|
expect(subject.send("flag?", "--debug")).to eq false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user