First Check
Commit to Help
Description
Hi,
I'd like to use typed-settings https://typed-settings.readthedocs.io/en/latest/guides/click.html#command-line-arguments-with-click with Typer. It has a decorator to generate click options from the settings object see the link to typed-settings.
I tried to include the click app in typer https://typer.tiangolo.com/tutorial/using-click/#including-a-typer-app-in-a-click-app but then I'm essentially using click and not Typer.
Wanted Solution
I would like to be able to add options from typed-settings Object in a similar style as it is described in docs.
It looks like what am I describing is the ability to dynamically set options from an object. I guess it is similar to #305 #86 (comment)
Here is what typed-settings usage looks like
import click
import os
import typed_settings as ts
os.environ['EXAMPLE_SPAM'] = "23"
@ts.settings
class Settings:
spam: int = 42
@click.command()
@ts.click_options(Settings, "example")
def cli(settings: Settings):
print(settings)
# As you can see, an option is generated for each setting:
import click.testing
runner = click.testing.CliRunner()
print(runner.invoke(cli, ["--help"]).output)
output
Usage: cli [OPTIONS]
Options:
--spam INTEGER [default: 23]
--help Show this message and exit.
print(runner.invoke(cli, ["--spam=3"]).output)
Settings(spam=3)
Wanted Code
import typer
import os
os.environ['EXAMPLE_SPAM'] = "23"
import typed_settings as ts
@ts.settings
class Settings:
spam: int = 42
app = typer.Typer()
@app.command()
def dynamic_options(settings:Settings=typer.Options()): # load options from the class
print(settings)
Alternatives
No response
Operating System
Linux
Operating System Details
No response
Typer Version
0.6.1
Python Version
3.9
Additional Context
First Check
Commit to Help
Description
Hi,
I'd like to use
typed-settingshttps://typed-settings.readthedocs.io/en/latest/guides/click.html#command-line-arguments-with-click with Typer. It has a decorator to generate click options from the settings object see the link totyped-settings.I tried to include the click app in typer https://typer.tiangolo.com/tutorial/using-click/#including-a-typer-app-in-a-click-app but then I'm essentially using click and not Typer.
Wanted Solution
I would like to be able to add options from typed-settings Object in a similar style as it is described in docs.
It looks like what am I describing is the ability to dynamically set options from an object. I guess it is similar to #305 #86 (comment)
Here is what typed-settings usage looks like
output
Wanted Code
Alternatives
No response
Operating System
Linux
Operating System Details
No response
Typer Version
0.6.1
Python Version
3.9
Additional Context