Rubocop: Don't show a stracktrace for invalid command-line params

Created on 19 Apr 2018  路  3Comments  路  Source: rubocop-hq/rubocop

Expected behavior

It'd be nice to get some helpful message when you mistype some CLI param.

Actual behavior

You get an ugly scary stacktrace.

rubocop --show-copss
invalid option: --show-copss
/Users/bozhidar/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.55.0/lib/rubocop/options.rb:21:in `parse'
/Users/bozhidar/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.55.0/lib/rubocop/cli.rb:37:in `run'
/Users/bozhidar/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.55.0/bin/rubocop:13:in `block in <top (required)>'
/Users/bozhidar/.rbenv/versions/2.4.1/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
/Users/bozhidar/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rubocop-0.55.0/bin/rubocop:12:in `<top (required)>'
/Users/bozhidar/.rbenv/versions/2.4.1/bin/rubocop:22:in `load'
/Users/bozhidar/.rbenv/versions/2.4.1/bin/rubocop:22:in `<main>'

Steps to reproduce the problem

Just type something like rubocop --foo.

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.55.0 (using Parser 2.5.0.0, running on ruby 2.4.2 x86_64-linux)
enhancement good first issue

All 3 comments

How about removing the stacktrace, keeping the 'invalid option' message, and adding something like 'For usage information, use --help'?

...or adding a did you mean-like suggestion? WDYT?

I'm fine with both approaches.

Was this page helpful?
0 / 5 - 0 ratings