man: Use Parser to parse args

This commit is contained in:
Gautham Goli 2018-03-24 21:26:16 +05:30
parent 2ec684a123
commit 78b41b07f1

View File

@ -10,6 +10,7 @@
require "formula" require "formula"
require "erb" require "erb"
require "ostruct" require "ostruct"
require "cli_parser"
module Homebrew module Homebrew
module_function module_function
@ -19,9 +20,14 @@ module Homebrew
TARGET_DOC_PATH = HOMEBREW_REPOSITORY/"docs" TARGET_DOC_PATH = HOMEBREW_REPOSITORY/"docs"
def man def man
@args = Homebrew::CLI::Parser.new do
switch "--fail-if-changed"
switch "--link"
end.parse
raise UsageError unless ARGV.named.empty? raise UsageError unless ARGV.named.empty?
if ARGV.flag? "--link" if @args.link?
odie "`brew man --link` is now done automatically by `brew update`." odie "`brew man --link` is now done automatically by `brew update`."
end end
@ -29,7 +35,7 @@ module Homebrew
if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages" if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages"
puts "No changes to manpage output detected." puts "No changes to manpage output detected."
elsif ARGV.include?("--fail-if-changed") elsif @args.fail_if_changed?
Homebrew.failed = true Homebrew.failed = true
end end
end end
@ -88,7 +94,7 @@ module Homebrew
# Set the manpage date to the existing one if we're checking for changes. # Set the manpage date to the existing one if we're checking for changes.
# This avoids the only change being e.g. a new date. # This avoids the only change being e.g. a new date.
date = if ARGV.include?("--fail-if-changed") && date = if @args.fail_if_changed? &&
target.extname == ".1" && target.exist? target.extname == ".1" && target.exist?
/"(\d{1,2})" "([A-Z][a-z]+) (\d{4})" "#{organisation}" "#{manual}"/ =~ target.read /"(\d{1,2})" "([A-Z][a-z]+) (\d{4})" "#{organisation}" "#{manual}"/ =~ target.read
Date.parse("#{Regexp.last_match(1)} #{Regexp.last_match(2)} #{Regexp.last_match(3)}") Date.parse("#{Regexp.last_match(1)} #{Regexp.last_match(2)} #{Regexp.last_match(3)}")