release-notes: Use Parser to parse args

This commit is contained in:
Gautham Goli 2018-03-24 19:21:10 +05:30
parent 2ec684a123
commit 93481ab491

View File

@ -5,10 +5,16 @@
#: #:
#: If `--markdown` is passed, output as a Markdown list. #: If `--markdown` is passed, output as a Markdown list.
require "cli_parser"
module Homebrew module Homebrew
module_function module_function
def release_notes def release_notes
args = Homebrew::CLI::Parser.new do
switch "--markdown"
end.parse
previous_tag = ARGV.named.first previous_tag = ARGV.named.first
previous_tag ||= Utils.popen_read("git tag --list --sort=-version:refname") previous_tag ||= Utils.popen_read("git tag --list --sort=-version:refname")
.lines.first.chomp .lines.first.chomp
@ -28,7 +34,7 @@ module Homebrew
s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*}, s.gsub(%r{.*Merge pull request #(\d+) from ([^/]+)/[^>]*(>>)*},
"https://github.com/Homebrew/brew/pull/\\1 (@\\2)") "https://github.com/Homebrew/brew/pull/\\1 (@\\2)")
end end
if ARGV.include?("--markdown") if args.markdown?
output.map! do |s| output.map! do |s|
/(.*\d)+ \(@(.+)\) - (.*)/ =~ s /(.*\d)+ \(@(.+)\) - (.*)/ =~ s
"- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})" "- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})"