mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
cli_parser: Add class method to make options declaration more readable
This commit is contained in:
parent
98f6f6b7d2
commit
ed387572ec
@ -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
|
||||
|
@ -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?
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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?
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user