Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cat: Use CLI::Parser to parse args #5560

Merged
merged 1 commit into from
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion Library/Homebrew/cmd/cat.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeMcQuaid seems like brew cat accepts other CLI args of cat command. What options do we plan on supporting ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GauthamGoli I think we can avoid supporting any arguments really; I don't think they are widely used.

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/test/cmd/help_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

Expand All @@ -40,7 +40,7 @@
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
Expand Down