From 78b41b07f12d503bb130170f1cde87176e8fec0c Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 24 Mar 2018 21:26:16 +0530 Subject: [PATCH] man: Use Parser to parse args --- Library/Homebrew/dev-cmd/man.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 109037d8eb..67b9336cad 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -10,6 +10,7 @@ require "formula" require "erb" require "ostruct" +require "cli_parser" module Homebrew module_function @@ -19,9 +20,14 @@ module Homebrew TARGET_DOC_PATH = HOMEBREW_REPOSITORY/"docs" def man + @args = Homebrew::CLI::Parser.new do + switch "--fail-if-changed" + switch "--link" + end.parse + raise UsageError unless ARGV.named.empty? - if ARGV.flag? "--link" + if @args.link? odie "`brew man --link` is now done automatically by `brew update`." end @@ -29,7 +35,7 @@ module Homebrew if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages" puts "No changes to manpage output detected." - elsif ARGV.include?("--fail-if-changed") + elsif @args.fail_if_changed? Homebrew.failed = true end end @@ -88,7 +94,7 @@ module Homebrew # 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. - date = if ARGV.include?("--fail-if-changed") && + date = if @args.fail_if_changed? && target.extname == ".1" && target.exist? /"(\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)}")