Merge pull request #5560 from GauthamGoli/cat-args

cat: Use CLI::Parser to parse args
This commit is contained in:
Gautham Goli 2019-01-20 19:50:56 +05:30 committed by GitHub
commit 70c5b6f804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -1,16 +1,29 @@
#: * `cat` <formula>:
#: Display the source to <formula>.
require "cli_parser"
module Homebrew
module_function
def cat_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`cat` <formula>
Display the source to <formula>.
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

View File

@ -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