From 382b5447d8695856256750e1af587dd9976a14b3 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 23 Jan 2019 09:20:49 +0530 Subject: [PATCH] gits-logs: Use CLI::Parser to parse args --- Library/Homebrew/cmd/gist-logs.rb | 34 ++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 975acbd65d..d791924182 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -18,11 +18,39 @@ require "formula" require "system_config" require "stringio" require "socket" +require "cli_parser" module Homebrew module_function + def gist_logs_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `gist-logs` [] : + + Upload logs for a failed build of to a new Gist. + + is usually the name of the formula to install, but it can be specified + in several different ways. See [SPECIFYING FORMULAE](#specifying-formulae). + + If no logs are found, an error message is presented. + EOS + switch "--with-hostname", + description: "Include the hostname in the Gist." + switch "-n", "--new-issue", + description: "Automatically create a new issue in the appropriate GitHub repository as "\ + "well as creating the Gist." + switch "-p", "--private", + description: "The Gist will be marked private and will not appear in listings but will "\ + "be accessible with the link." + switch :verbose + switch :debug + end + end + def gistify_logs(f) + gist_logs_args.parse + files = load_logs(f.logs) build_time = f.logs.ctime timestamp = build_time.strftime("%Y-%m-%d_%H-%M-%S") @@ -60,7 +88,7 @@ module Homebrew end url = create_gist(files, descr) - if ARGV.include?("--new-issue") || ARGV.switch?("n") + if args.new_issue? url = create_issue(f.tap, "#{f.name} failed to build on #{MacOS.full_version}", url) end @@ -72,7 +100,7 @@ module Homebrew s = <<~EOS Homebrew build logs for #{f.full_name} on #{OS_VERSION} EOS - if ARGV.include?("--with-hostname") + if args.with_hostname? hostname = Socket.gethostname s << "Host: #{hostname}\n" end @@ -114,7 +142,7 @@ module Homebrew end def create_private? - ARGV.include?("--private") || ARGV.switch?("p") + args.private? end def create_gist(files, description)