cli_parser: Add class method to make options declaration more readable

This commit is contained in:
Gautham Goli 2018-03-25 17:48:22 +05:30
parent 98f6f6b7d2
commit ed387572ec
7 changed files with 16 additions and 12 deletions

View File

@ -4,6 +4,10 @@ require "ostruct"
module Homebrew
module CLI
class Parser
def self.parse(&block)
new(&block).parse
end
def initialize(&block)
@parser = OptionParser.new
@parsed_args = OpenStruct.new

View File

@ -55,7 +55,7 @@ module Homebrew
module_function
def audit
args = Homebrew::CLI::Parser.new do
args = Homebrew::CLI::Parser.parse do
switch "--strict"
switch "--online"
switch "--new-formula"
@ -67,7 +67,7 @@ module Homebrew
comma_array "--except"
comma_array "--only-cops"
comma_array "--except-cops"
end.parse
end
Homebrew.auditing = true
inject_dump_stats!(FormulaAuditor, /^audit_/) if args.audit_debug?

View File

@ -11,9 +11,9 @@ module Homebrew
module_function
def edit
args = Homebrew::CLI::Parser.new do
args = Homebrew::CLI::Parser.parse do
switch "--force"
end.parse
end
unless (HOMEBREW_REPOSITORY/".git").directory?
raise <<~EOS

View File

@ -23,10 +23,10 @@ module Homebrew
module_function
def irb
args = Homebrew::CLI::Parser.new do
args = Homebrew::CLI::Parser.parse do
switch "--examples"
switch "--pry", env: :pry
end.parse
end
if args.examples?
puts "'v8'.f # => instance of the v8 formula"

View File

@ -20,10 +20,10 @@ module Homebrew
TARGET_DOC_PATH = HOMEBREW_REPOSITORY/"docs"
def man
@args = Homebrew::CLI::Parser.new do
@args = Homebrew::CLI::Parser.parse do
switch "--fail-if-changed"
switch "--link"
end.parse
end
raise UsageError unless ARGV.named.empty?

View File

@ -11,9 +11,9 @@ module Homebrew
module_function
def release_notes
args = Homebrew::CLI::Parser.new do
args = Homebrew::CLI::Parser.parse do
switch "--markdown"
end.parse
end
previous_tag = ARGV.named.first
previous_tag ||= Utils.popen_read("git tag --list --sort=-version:refname")

View File

@ -23,7 +23,7 @@ module Homebrew
module_function
def tests
args = Homebrew::CLI::Parser.new do
args = Homebrew::CLI::Parser.parse do
switch "--no-compat"
switch "--generic"
switch "-v", "--verbose"
@ -31,7 +31,7 @@ module Homebrew
switch "--online"
flag "--only", required: true
flag "--seed", required: true
end.parse
end
HOMEBREW_LIBRARY_PATH.cd do
ENV.delete("HOMEBREW_VERBOSE")