Extract out arg parsing method to <cmd>_args method

This commit is contained in:
Gautham Goli 2018-07-30 18:25:38 +05:30
parent 32e5a5686b
commit b6c456b681
No known key found for this signature in database
GPG Key ID: 6A9ABBC284468364
16 changed files with 97 additions and 35 deletions

View File

@ -94,10 +94,11 @@ module Homebrew
@parser.to_s
end
def parse(cmdline_args)
def parse(cmdline_args = ARGV)
remaining_args = @parser.parse(cmdline_args)
check_constraint_violations
Homebrew.args[:remaining] = remaining_args
@parser
end
private

View File

@ -52,8 +52,8 @@ require "cli_parser"
module Homebrew
module_function
def audit
Homebrew::CLI::Parser.parse do
def audit_args
Homebrew::CLI::Parser.new do
banner <<~EOS
Usage: brew audit [options] [<formulae>]
@ -61,6 +61,7 @@ module Homebrew
run before submitting a new formula.
If no <formulae> are provided, all of them are checked.
EOS
switch "--strict", description: "Run additional style checks, including Rubocop style checks."
switch "--online", description: "Run additional slower style checks that require a\nnetwork connection."
@ -76,6 +77,10 @@ module Homebrew
switch :verbose
switch :debug
end
end
def audit
audit_args.parse
Homebrew.auditing = true
inject_dump_stats!(FormulaAuditor, /^audit_/) if args.audit_debug?

View File

@ -69,8 +69,8 @@ MAXIMUM_STRING_MATCHES = 100
module Homebrew
module_function
def bottle
Homebrew::CLI::Parser.parse do
def bottle_args
Homebrew::CLI::Parser.new do
switch "--merge"
switch "--skip-relocation"
switch "--force-core-tap"
@ -84,6 +84,10 @@ module Homebrew
switch :debug
flag "--root-url"
end
end
def bottle
bottle_args.parse
return merge if args.merge?

View File

@ -47,8 +47,8 @@ require "cli_parser"
module Homebrew
module_function
def bump_formula_pr
Homebrew::CLI::Parser.parse do
def bump_formula_pr_args
Homebrew::CLI::Parser.new do
switch "--devel"
switch "-n", "--dry-run"
switch "--write"
@ -70,6 +70,10 @@ module Homebrew
conflicts "--url", "--tag"
end
end
def bump_formula_pr
bump_formula_pr_args.parse
# As this command is simplifying user run commands then let's just use a
# user path, too.

View File

@ -27,9 +27,8 @@ require "cli_parser"
module Homebrew
module_function
# Create a formula from a tarball URL
def create
Homebrew::CLI::Parser.parse do
def create_args
Homebrew::CLI::Parser.new do
switch "--autotools"
switch "--cmake"
switch "--meson"
@ -42,6 +41,12 @@ module Homebrew
flag "--set-version="
flag "--tap="
end
end
# Create a formula from a tarball URL
def create
create_args.parse
raise UsageError if ARGV.named.empty?
# Ensure that the cache exists so we can fetch the tarball

View File

@ -10,12 +10,16 @@ require "cli_parser"
module Homebrew
module_function
def edit
Homebrew::CLI::Parser.parse do
def edit_args
Homebrew::CLI::Parser.new do
switch :force
switch :verbose
switch :debug
end
end
def edit
edit_args.parse
unless (HOMEBREW_REPOSITORY/".git").directory?
raise <<~EOS

View File

@ -7,11 +7,15 @@ require "cli_parser"
module Homebrew
module_function
def formula
Homebrew::CLI::Parser.parse do
def formula_args
Homebrew::CLI::Parser.new do
switch :debug
switch :verbose
end
end
def formula
formula_args.parse
raise FormulaUnspecifiedError if ARGV.named.empty?

View File

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

View File

@ -19,13 +19,17 @@ require "cli_parser"
module Homebrew
module_function
def linkage
Homebrew::CLI::Parser.parse do
def linkage_args
Homebrew::CLI::Parser.new do
switch "--test"
switch "--reverse"
switch :verbose
switch :debug
end
end
def linkage
linkage_args.parse
CacheStoreDatabase.use(:linkage) do |db|
kegs = if ARGV.kegs.empty?

View File

@ -11,6 +11,7 @@ require "formula"
require "erb"
require "ostruct"
require "cli_parser"
require "dev-cmd/audit"
module Homebrew
module_function
@ -19,11 +20,15 @@ module Homebrew
TARGET_MAN_PATH = HOMEBREW_REPOSITORY/"manpages"
TARGET_DOC_PATH = HOMEBREW_REPOSITORY/"docs"
def man
Homebrew::CLI::Parser.parse do
def man_args
Homebrew::CLI::Parser.new do
switch "--fail-if-changed"
switch "--link"
end
end
def man
man_args.parse
raise UsageError unless ARGV.named.empty?
@ -64,7 +69,7 @@ module Homebrew
variables = OpenStruct.new
variables[:commands] = path_glob_commands("#{HOMEBREW_LIBRARY_PATH}/cmd/*.{rb,sh}")
variables[:developer_commands] = path_glob_commands("#{HOMEBREW_LIBRARY_PATH}/dev-cmd/*.{rb,sh}")
variables[:developer_commands] = [Homebrew.send(:audit_args).summary] + path_glob_commands("#{HOMEBREW_LIBRARY_PATH}/dev-cmd/*.{rb,sh}")
readme = HOMEBREW_REPOSITORY/"README.md"
variables[:lead_maintainer] =
readme.read[/(Homebrew's lead maintainer .*\.)/, 1]

View File

@ -7,11 +7,15 @@ require "cli_parser"
module Homebrew
module_function
def mirror
Homebrew::CLI::Parser.parse do
def mirror_args
Homebrew::CLI::Parser.new do
switch :debug
switch :verbose
end
end
def mirror
mirror_args.parse
odie "This command requires at least formula argument!" if ARGV.named.empty?

View File

@ -72,10 +72,8 @@ end
module Homebrew
module_function
def pull
odie "You meant `git pull --rebase`." if ARGV[0] == "--rebase"
Homebrew::CLI::Parser.parse do
def pull_args
Homebrew::CLI::Parser.new do
switch "--bottle"
switch "--bump"
switch "--clean"
@ -90,6 +88,12 @@ module Homebrew
flag "--bintray-org="
flag "--test-bot-user="
end
end
def pull
odie "You meant `git pull --rebase`." if ARGV[0] == "--rebase"
pull_args.parse
if ARGV.named.empty?
odie "This command requires at least one argument containing a URL or pull request number"

View File

@ -10,10 +10,13 @@ require "cli_parser"
module Homebrew
module_function
def release_notes
Homebrew::CLI::Parser.parse do
def release_notes_args
Homebrew::CLI::Parser.new do
switch "--markdown"
end
end
def release_notes
release_notes_args.parse
previous_tag = ARGV.named.first
previous_tag ||= Utils.popen_read(

View File

@ -15,11 +15,15 @@ module Homebrew
path.write content
end
def tap_new
Homebrew::CLI::Parser.parse do
def tap_new_args
Homebrew::CLI::Parser.new do
switch :debug
switch :verbose
end
end
def tap_new
tap_new_args.parse
raise "A tap argument is required" if ARGV.named.empty?

View File

@ -21,8 +21,8 @@ require "fileutils"
module Homebrew
module_function
def tests
Homebrew::CLI::Parser.parse do
def tests_args
Homebrew::CLI::Parser.new do
switch "--no-compat"
switch "--generic"
switch "--coverage"
@ -32,6 +32,9 @@ module Homebrew
flag "--only="
flag "--seed="
end
end
def tests
tests_args.parse
HOMEBREW_LIBRARY_PATH.cd do
ENV.delete("HOMEBREW_COLOR")

View File

@ -19,8 +19,8 @@ require "cli_parser"
module Homebrew
module_function
def update_test
Homebrew::CLI::Parser.parse do
def update_test_args
Homebrew::CLI::Parser.new do
switch "--to-tag"
switch "--keep-tmp"
switch :verbose
@ -28,6 +28,10 @@ module Homebrew
flag "--commit="
flag "--before="
end
end
def update_test
update_test_args.parse
ENV["HOMEBREW_UPDATE_TEST"] = "1"