style: Use CLI::Parser to parse args
This commit is contained in:
parent
fd8206567b
commit
c6c3916ddb
@ -110,7 +110,7 @@ module Homebrew
|
|||||||
if name.length == 1
|
if name.length == 1
|
||||||
"-#{name}"
|
"-#{name}"
|
||||||
else
|
else
|
||||||
"--#{name}"
|
"--#{name.tr("_", "-")}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -20,11 +20,41 @@
|
|||||||
require "json"
|
require "json"
|
||||||
require "open3"
|
require "open3"
|
||||||
require "style"
|
require "style"
|
||||||
|
require "cli_parser"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
def style_args
|
||||||
|
Homebrew::CLI::Parser.new do
|
||||||
|
usage_banner <<~EOS
|
||||||
|
`style` [<options>] [<files>|<taps>|<formulae>]
|
||||||
|
|
||||||
|
Check formulae or files for conformance to Homebrew style guidelines.
|
||||||
|
|
||||||
|
Lists of <files>, <taps> and <formulae> may not be combined. If none are
|
||||||
|
provided, `style` will run style checks on the whole Homebrew library,
|
||||||
|
including core code and all formulae.
|
||||||
|
EOS
|
||||||
|
switch "--fix",
|
||||||
|
description: "Fix style violations automatically using RuboCop's auto-correct feature."
|
||||||
|
switch "--display-cop-names",
|
||||||
|
description: "Include the RuboCop cop name for each violation in the output."
|
||||||
|
comma_array "--only-cops",
|
||||||
|
description: "Specify a comma-separated <cops> list to check for violations of only the "\
|
||||||
|
"listed RuboCop cops."
|
||||||
|
comma_array "--except-cops",
|
||||||
|
description: "Specify a comma-separated <cops> list to skip checking for violations of the "\
|
||||||
|
"listed RuboCop cops."
|
||||||
|
switch :verbose
|
||||||
|
switch :debug
|
||||||
|
conflicts "--only-cops", "--except-cops"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def style
|
def style
|
||||||
|
style_args.parse
|
||||||
|
|
||||||
target = if ARGV.named.empty?
|
target = if ARGV.named.empty?
|
||||||
nil
|
nil
|
||||||
elsif ARGV.named.any? { |file| File.exist? file }
|
elsif ARGV.named.any? { |file| File.exist? file }
|
||||||
@ -35,18 +65,15 @@ module Homebrew
|
|||||||
ARGV.formulae.map(&:path)
|
ARGV.formulae.map(&:path)
|
||||||
end
|
end
|
||||||
|
|
||||||
only_cops = ARGV.value("only-cops").to_s.split(",")
|
only_cops = args.only_cops
|
||||||
except_cops = ARGV.value("except-cops").to_s.split(",")
|
except_cops = args.except_cops
|
||||||
if !only_cops.empty? && !except_cops.empty?
|
|
||||||
odie "--only-cops and --except-cops cannot be used simultaneously!"
|
|
||||||
end
|
|
||||||
|
|
||||||
options = { fix: ARGV.flag?("--fix") }
|
options = { fix: args.fix? }
|
||||||
if !only_cops.empty?
|
if only_cops
|
||||||
options[:only_cops] = only_cops
|
options[:only_cops] = only_cops
|
||||||
elsif !except_cops.empty?
|
elsif except_cops
|
||||||
options[:except_cops] = except_cops
|
options[:except_cops] = except_cops
|
||||||
elsif only_cops.empty? && except_cops.empty?
|
elsif only_cops.nil? && except_cops.nil?
|
||||||
options[:except_cops] = %w[FormulaAudit
|
options[:except_cops] = %w[FormulaAudit
|
||||||
FormulaAuditStrict
|
FormulaAuditStrict
|
||||||
NewFormulaAudit]
|
NewFormulaAudit]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user