Is it possible to have Thor complain about misspelled/unrecognized command line options?
Example:
maid --slient # Oops! Misspelled. It should give a warning or usage info.
maid --silent # Do the behavior I programmed for the "silent" option.
Thor is really nice, but it isn't too helpful for me if it just ignores input it doesn't know how to handle. Maid also has an option to specify a file of Maid rules like so:
maid --rules=rules.rb # Good
maid -r rules.rb # Short version
maid rules.rb # Oops! That's not valid. It should give a warning or usage info.
What can I do to make Thor complain in the two cases above?
The code for the Maid gem is on GitHub at http://github.com/benjaminoakes/maid
I got a tweet from Yehuda Katz. (Thanks again!) Here's the solution:
class YourApp < Thor
check_unknown_options!
# ...
end
I tested and added it into my project. Here's the new behavior:
$ maid --slient
Unknown switches '--slient'
$ maid rules.rb
Could not find task "rules.rb".
See the full code on GitHub.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With