-
Notifications
You must be signed in to change notification settings - Fork 33
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
Interest in better support for sub parsers #67
Comments
If need support for subcommands, you can try other libraries like clikt |
I was able to do it by having 2 classes and composing them.
but this might not cover all the use cases you are looking for. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I (unfortunately) write Python almost every day at work, and we use Argparse there most of the time.
Argparse has wonderful support for subparsers, but it seems fairly tedious to do with this library.
Say I'm writing a cli for a program like this:
And I want a separate parser for
--add-task
. It will have its own positional arguments and its own help menu. Something like this:Doesn't seem too unreasonable I think.
But from going through the docs, it doesn't appear this functionality is built in. To add this functionality on my own, I end up doing a bunch of array splicing, and then sending that task to the parser I want to run.
It's not particularly nice, but I'm getting it done with this code:
https://gitlab.com/time-tracker-utils/TerminalTimetrackerClient/blob/master/src/main/kotlin/Client.kt#L9
I'm aware I could use a positional list for the -a option, but that surrenders more control.
It would be very nice if I could do something like this:
Where TaskParser is something like this:
But this does not seem to be very easy.
I'm currently using this library for a personal project here: https://gitlab.com/time-tracker-utils/TerminalTimetrackerClient/tree/master and it's been great so far, but this was a large gripe that cost me a few hours today trying to understand a good way of adding subparsers.
In the end, I couldn't find one.
Please advise - and if it doesn't exist, I might make my own PR in the coming weeks.
The text was updated successfully, but these errors were encountered: