From 9d287483b77c112b40fe0546d4d65cdd27c23cb0 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Fri, 18 Jan 2019 22:17:46 +0530 Subject: [PATCH] cat: Use CLI::Parser to parse args --- Library/Homebrew/cmd/cat.rb | 15 ++++++++++++++- Library/Homebrew/test/cmd/help_spec.rb | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/cat.rb b/Library/Homebrew/cmd/cat.rb index 7439869d30..5cf7077cc9 100644 --- a/Library/Homebrew/cmd/cat.rb +++ b/Library/Homebrew/cmd/cat.rb @@ -1,16 +1,29 @@ #: * `cat` : #: Display the source to . +require "cli_parser" + module Homebrew module_function + def cat_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `cat` + + Display the source to . + EOS + end + end + def cat + cat_args.parse # do not "fix" this to support multiple arguments, the output would be # unparsable, if the user wants to cat multiple formula they can call # brew cat multiple times. formulae = ARGV.formulae raise FormulaUnspecifiedError if formulae.empty? - raise "`brew cat` doesn't support multiple arguments" if formulae.size > 1 + raise "`brew cat` doesn't support multiple arguments" if args.remaining.size > 1 cd HOMEBREW_REPOSITORY exec "cat", formulae.first.path, *ARGV.options_only diff --git a/Library/Homebrew/test/cmd/help_spec.rb b/Library/Homebrew/test/cmd/help_spec.rb index e3460dec0f..ab80b69f01 100644 --- a/Library/Homebrew/test/cmd/help_spec.rb +++ b/Library/Homebrew/test/cmd/help_spec.rb @@ -14,7 +14,7 @@ describe "brew", :integration_test do it "prints help for a documented Ruby command" do expect { brew "help", "cat" } - .to output(/^brew cat/).to_stdout + .to output(/^Usage: brew cat/).to_stdout .and be_a_success end @@ -40,7 +40,7 @@ describe "brew", :integration_test do describe "cat" do it "prints help when no argument is given" do expect { brew "cat" } - .to output(/^brew cat/).to_stderr + .to output(/^Usage: brew cat/).to_stderr .and be_a_failure end end