diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index c6eb823c30584..a0c633aedf755 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 1ad69cff7d774..25575e2ec2dd3 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -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 @@ 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? diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index 53af54811b13a..0861a4bb1edf6 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb index b27cb4ab80a15..1d6b0a5142d5f 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -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" diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 67b9336cad1e7..a54ab89e3cea3 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -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? diff --git a/Library/Homebrew/dev-cmd/release-notes.rb b/Library/Homebrew/dev-cmd/release-notes.rb index d4108ce8dbda7..892a4a83e1887 100644 --- a/Library/Homebrew/dev-cmd/release-notes.rb +++ b/Library/Homebrew/dev-cmd/release-notes.rb @@ -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") diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index a1a6b7fc5b567..57c00dafc7702 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -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 @@ def tests switch "--online" flag "--only", required: true flag "--seed", required: true - end.parse + end HOMEBREW_LIBRARY_PATH.cd do ENV.delete("HOMEBREW_VERBOSE")