gli
gli copied to clipboard
Define "default" (and only) command to execute
It'll be nice to have a "default" global command that will be execute, if there are no other commands defined in the interface.
We have ton of utilities that are a "single purpose" ones. They receive a bunch of flags but have only one command to execute
GLI isn't for that sort of app. GLI is for an app that has a series of subcommands. If you just want a simple command line app without subcommands, OptionParser is pretty good, though my other lib davetron5000/optparse-plus makes it really easy to make an app like that.
I personally want a mix of the two. Ideally I want to be able to take in a wildcard argument without passing anything else in. Like I'm defining shortcuts that can be used later as a wildcard.
gli WILDCARD
gli standard-cmd
Is something like that possible in GLI?
What does WILDCARD mean in this context? Can you give a more specific example?
All that said, GLI really is designed to always be given at least one subcommand.
WILDCARD would be an argument, any text that is passed in that doesn't match a predefined command
Ah, ok. It's not really designed for that but you might be able to implement it yourself. For reference, here is how GLI locates a command based on the command line:
https://github.com/davetron5000/gli/blob/dd79e12a041aed8791a4ba9c8ec9a875075914d1/lib/gli/command_finder.rb#L15-L36
You could rescue UnknownCommand and do something else. If you implement the on_error handler, you can check to see what exception you got. If you can handle whatever the value is, kick off your code and return false.
The one thing you couldn't do easily is detect the name of the unknown command without parsing the message of that exception. I suppose UnknownException could be modified to include an attribute that held the command name it could not find.