question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Idea: Allow flags to take boolean values

See original GitHub issue

Suppose 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sschuberthcommented, Mar 1, 2021

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.

0reactions
sschuberthcommented, Mar 1, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are Boolean Flags on Methods a Code Smell? | Blog
Boolean flags reveal that your function doesn't just do one thing it does at least two bifurcated on the input Boolean. nici93 •...
Read more >
Avoid Passing Booleans to Functions - Alex Kondov
Flags are not a best practice because they reduce the cohesion of a function. It does more than one thing. Booleans make it...
Read more >
Unit 5 - Lesson 15 #11: Using A Boolean Variable As A Flag
Arduino Programming Tutorial: Use of Flags in arduino || Arduino flags. Electronic Clinic. Electronic Clinic. •. •. 8K views 4 years ago ...
Read more >
Flags
A flag is a logical concept, not a special type of variable. ... should only have 2 values, and the Boolean values are...
Read more >
Best way to handle boolean flags - java - Stack Overflow
Along with this i have used a bitset ( flagSet ). Instead of setting hard coded index values in bitset i am taking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found