Allow to specify a bool option as a key value pair #704
Replies: 3 comments 1 reply
-
I tested the following code: @app.command(name="test")
def tes(ver: bool = Option(
False, "--verify", "-v",
help="Verify SSL Certificates"
)):
print("ver is", ver) run and @app.command(name="test")
def tes(ver: bool = Option(
False, "--verify", "-v",
is_flag=True,
help="Verify SSL Certificates"
)):
print("ver is", ver) |
Beta Was this translation helpful? Give feedback.
-
But what I want to run is @app.command(name="test")
def tes(ver: bool = Option(
False, "--verify", "-v",
is_flag=False,
help="Verify SSL Certificates"
)):
print("ver is", ver) |
Beta Was this translation helpful? Give feedback.
-
Poking around in the code, I see that
Does this mean that passing booleans as values is not supported? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
I could not find an easy issue where I could contribute. But I did a one time sponsorship of $ 20.- to make up for that.
Example Code
Then, calling the script:
$ python scratch/typer-key-value.py --is-true=False Error: Option '--is-true' does not take a value
Other ideas such as changing the type annotation to
str
is also hacky.Description
I would like to specify a bool option as a key value pair. The use case for this is that in certains circumstances, it's only possible to specify key value pairs for a command line program. In my case, starting a training job on Sagemaker, the hyper-parameters have to be supplied as key-value pairs. So if I have a boolean hyper-parameter, I must type it as a string and then later convert it, which is a workaround.
Operating System
macOS
Operating System Details
No response
Typer Version
0.9.0
Python Version
3.11.4
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions