commander-rb / commander

The complete solution for Ruby command-line executables
MIT License
822 stars 74 forks source link

Prevent default command from running when user specifies an unknown command #74

Closed roberts1000 closed 5 years ago

roberts1000 commented 5 years ago

If I use default_command, any time someone runs an unknown command, Commander executes the default command. Is there any way to make Commander operate similar to bundler, and have it throw an error in this situation? I only want it run the default command when no sub command is specified.

$ bundle unknown_command
Could not find command "unknown_command".

$ bundle
Fetching gem metadata from https://rubygems.org/........
ggilder commented 5 years ago

I'm afraid that's the way the feature is designed to work. I'm not sure if it's a good idea to change that as it could break the way people expect it to work. I'm open to being convinced, though. 😄

roberts1000 commented 5 years ago

Thanks for confirming. Could we potentially have default_command take an optional argument that can change the behavior?

default_command :foo, strict: true

Then the old behavior can continue to work as-is, but people can opt-in to the new behavior if they want it.

ggilder commented 5 years ago

Yeah, something like that sounds reasonable. Would you like to take a stab at implementing that and make a pull request?

roberts1000 commented 5 years ago

Sounds good. I'll take a look as soon as I can. Thanks for considering the enhancement.