Idea: Allow flags to take boolean values
See original GitHub issueSuppose I have a flag like
val verbose by option().flag()
which can be enabled / set to true
by passing --verbose
on the command line. Then sometimes, e.g. when using a UI frontend for a CLI tool where a “verbose” option can be set to “true” or “false” in a form, it would be slightly more convenient to simply pass on that boolean value to the clikt option like --verbose=${boolean_from_ui}
which expands to either --verbose=true
or -verbose=false
, instead of implementing logic to use --verbose
if the UI parameter is true
, and use an empty string / nothing if the UI parameter is false
.
So, would it be feasible to make flag options allow to take a boolean-ish value? I realize that in some cases like with a flag called “on” allowing something like --on=off
sounds odd; but then again you’d not have to use that syntax.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top GitHub Comments
No, I’m not aware of existing CLI tools that work that way out of my head. I’m trying to push innovative features to clikt 😉 That said, JCommander almost supports something like that, with its boolean options with an arity of 1, but then using no value for the options does not work anymore.
You’re right, with all the other features that clikt already supports, I also do not see a way to implement this unambiguously. Thanks for evaluating this idea together with me, but it seems fair to me to close this one.