Closed igormoochnick closed 3 months ago
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:
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.
closing as not a bug in GLI (though I totally understand the identified need - GLI just isn't the right lib for this)
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