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

Did you mean flag #6316

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -29,13 +29,17 @@
# destination = destination.upcase if upcase
# puts "Hello #{destination}!"
# ```

require "colorize"

class OptionParser
class Exception < ::Exception
end

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

Expand Down