Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli_parser: Add class method to make options declaration more readable #3980

Merged
merged 1 commit into from
Mar 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Library/Homebrew/cli_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
module Homebrew
module CLI
class Parser
def self.parse(&block)
new(&block).parse
end

def initialize(&block)
@parser = OptionParser.new
@parsed_args = OpenStruct.new
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -67,7 +67,7 @@ def audit
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?
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/edit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/man.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/release-notes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ 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"
switch "--coverage"
switch "--online"
flag "--only", required: true
flag "--seed", required: true
end.parse
end

HOMEBREW_LIBRARY_PATH.cd do
ENV.delete("HOMEBREW_VERBOSE")
Expand Down