Add :quiet, :verbose, :debug common switches to be specified
This commit is contained in:
parent
0f4e22e28d
commit
8ef1fb30a0
@ -16,6 +16,7 @@ module Homebrew
|
|||||||
|
|
||||||
def switch(*names, description: nil, env: nil)
|
def switch(*names, description: nil, env: nil)
|
||||||
description = option_to_description(*names) if description.nil?
|
description = option_to_description(*names) if description.nil?
|
||||||
|
names, env = common_switch(*names) if names.first.is_a?(Symbol)
|
||||||
@parser.on(*names, description) do
|
@parser.on(*names, description) do
|
||||||
enable_switch(*names)
|
enable_switch(*names)
|
||||||
end
|
end
|
||||||
@ -46,7 +47,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def option_to_description(*names)
|
def option_to_description(*names)
|
||||||
names.map { |name| name.sub(/\A--?/, "").tr("-", " ") }.sort.last
|
names.map { |name| name.to_s.sub(/\A--?/, "").tr("-", " ") }.sort.last
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse(cmdline_args = ARGV)
|
def parse(cmdline_args = ARGV)
|
||||||
@ -61,6 +62,15 @@ module Homebrew
|
|||||||
@parsed_args["#{option_to_name(name)}?"] = true
|
@parsed_args["#{option_to_name(name)}?"] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def common_switch(name)
|
||||||
|
case name
|
||||||
|
when :quiet then [["-q", "--quiet"], :quiet]
|
||||||
|
when :verbose then [["-v", "--verbose"], :verbose]
|
||||||
|
when :debug then [["-d", "--debug"], :debug]
|
||||||
|
else name
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -63,6 +63,8 @@ module Homebrew
|
|||||||
switch "--display-cop-names"
|
switch "--display-cop-names"
|
||||||
switch "--display-filename"
|
switch "--display-filename"
|
||||||
switch "-D", "--audit-debug", description: "Activates debugging and profiling"
|
switch "-D", "--audit-debug", description: "Activates debugging and profiling"
|
||||||
|
switch :verbose
|
||||||
|
switch :debug
|
||||||
comma_array "--only"
|
comma_array "--only"
|
||||||
comma_array "--except"
|
comma_array "--except"
|
||||||
comma_array "--only-cops"
|
comma_array "--only-cops"
|
||||||
|
@ -72,7 +72,6 @@ module Homebrew
|
|||||||
def bottle
|
def bottle
|
||||||
@args = Homebrew::CLI::Parser.parse do
|
@args = Homebrew::CLI::Parser.parse do
|
||||||
switch "--merge"
|
switch "--merge"
|
||||||
switch "-v", "--verbose"
|
|
||||||
switch "--skip-relocation"
|
switch "--skip-relocation"
|
||||||
switch "--force-core-tap"
|
switch "--force-core-tap"
|
||||||
switch "--no-rebuild"
|
switch "--no-rebuild"
|
||||||
@ -80,6 +79,7 @@ module Homebrew
|
|||||||
switch "--write"
|
switch "--write"
|
||||||
switch "--no-commit"
|
switch "--no-commit"
|
||||||
switch "--json"
|
switch "--json"
|
||||||
|
switch :verbose
|
||||||
flag "--root-url"
|
flag "--root-url"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,9 +2,14 @@ require_relative "../cli_parser"
|
|||||||
|
|
||||||
describe Homebrew::CLI::Parser do
|
describe Homebrew::CLI::Parser do
|
||||||
describe "test switch options" do
|
describe "test switch options" do
|
||||||
|
before do
|
||||||
|
allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1")
|
||||||
|
allow(ENV).to receive(:[]).with("HOMEBREW_VERBOSE")
|
||||||
|
end
|
||||||
|
|
||||||
subject(:parser) {
|
subject(:parser) {
|
||||||
described_class.new do
|
described_class.new do
|
||||||
switch "-v", "--verbose", description: "Flag for verbosity"
|
switch :verbose, description: "Flag for verbosity"
|
||||||
switch "--more-verbose", description: "Flag for higher verbosity"
|
switch "--more-verbose", description: "Flag for higher verbosity"
|
||||||
switch "--pry", env: :pry
|
switch "--pry", env: :pry
|
||||||
end
|
end
|
||||||
@ -37,7 +42,6 @@ describe Homebrew::CLI::Parser do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "maps environment var to an option" do
|
it "maps environment var to an option" do
|
||||||
allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1")
|
|
||||||
args = parser.parse([])
|
args = parser.parse([])
|
||||||
expect(args.pry?).to be true
|
expect(args.pry?).to be true
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user