-
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
Allow omitting mandatory parameters #40
Comments
I've been working on a change to add "subcommand" support (see #2 ). Do you think that would be sufficient for what you're trying to do? The user-interface would look slightly different. Instead of:
it would be:
In general, the format is:
This is similar to (and is based on) tools like |
Sub-command support seems like the cleaner approach than omission of required parameters. I would really love to see this, as right now most of my commands are optional (although at least one should be probably mandatory at any time). |
Subcommands are great, but I believe that it's not the right tool for the job here. Most programs don't work with subcommands and have instead some sort of "multiple usages" mindset, which I believe can be reasonably named the "anonymous subcommands" or "implicit subcommands" pattern. I believe a lot of programs want usages like this:
which corresponds to implicit "help", "version", and "default" subcommands. There is actually one such implicit subcommand already implemented in kotlin-argparser: the help flag. It'd be nice to generalize this behaviour, maybe by using mutually exclusive option groups, that would act like anonymous subcommands. A more simple implementation would be a special option type "standalone option" which would at least allow separating a single option from the rest, exactly like the help flag but for any custom option. This feature would be very useful to implement for instance:
|
Regarding the version flag, then I've recently made this PR: #70 |
If you have:
val configFile by parser.storing("--config", "-c", argName = "CONFIGFILE", help = "Configuration file") { asPath }
val version by parser.flagging("--version", help = "print version and exit")
You cannot specify only "--version" in command line - it will complain about "missing CONFIGFILE"
We need an option for allowing printing version.
Alternatively allow multiple configurations:
usage: --config CONFIGFILE
usage: --version
The text was updated successfully, but these errors were encountered: