Skip to content

Commit

Permalink
Implement 'With crystal foo.cr --flag, when --flag isn't found, menti…
Browse files Browse the repository at this point in the history
…on did you mean crystal foo.cr -- --flag' from PR crystal-lang#5291
  • Loading branch information
Ben Lewis committed Jun 30, 2018
1 parent d6ba746 commit cc52bb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion spec/std/option_parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ describe "OptionParser" do
end

it "raises on invalid option" do
expect_raises OptionParser::InvalidOption, "Invalid option: -j" do
suggestion = "(did you mean 'crystal foo.cr -- -j'?)".colorize.yellow.bold.to_s
expect_raises OptionParser::InvalidOption, "Invalid option: -j #{suggestion}" do
OptionParser.parse(["-f", "-j"]) do |opts|
opts.on("-f", "some flag") { }
end
Expand Down
6 changes: 5 additions & 1 deletion src/option_parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class OptionParser

class InvalidOption < Exception
def initialize(option)
super("Invalid option: #{option}")
super("Invalid option: #{option} #{
type.program.colorize(
"(did you mean 'crystal foo.cr -- #{option}')"
).yellow.bold
}")
end
end

Expand Down

0 comments on commit cc52bb0

Please sign in to comment.