Replies: 2 comments
-
Not sure that it's possible with typer directly, but if you have lots and lots of parameters, I can understand the want for a config file. In that case, if you still want a simple type annotated developer experience (which I can sympathize with), you could just use a |
Beta Was this translation helpful? Give feedback.
-
I think this can be solve by introducing mutually exclusive options: #140 If you don't have a lot of commands, you can solve this by adding separate commands that would read parameters from config file and call existing command functions: @app.command()
def connection(
name: str = typer.Option(),
display_name: str = typer.Option(),
service_account_json: str = typer.Option(),
ignored_users: str = typer.Option()
) -> None:
"""Connect the platform"""
pass
@app.command()
def connection_from_config():
"""Connect the platform. Read configuration from file"""
# read config from file
connection(name=name_from_config, ...) |
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
Example Code
Description
Hello, I am very new to Typer and have a question regarding the possibility of dynamic arguments or any suggestions :)
In the above code sample, I am trying to connect a platform with the CLI. The platform in example has to have
name
,display name
,service account json
and some other optional fields. However, if the command has too many arguments it looks messy and is a lot of work for user in case of positional arguments.What I want is to give user options. If a user has a
json
oryaml
file with config details I want to just read the values from there and disable input for required arguments, otherwise if the user doesn't have the file, they should pass all the arguments using the right flags(-- name xyz for example).This can depend on the first argument lets say
is_config_file_available: bool = typer.Option(False, help = "Do you want to load credentials from the config file?"),
If the user input here is True then they can pass the file path along and doesn't have to pass any other argument.
Is this possible to do with Typer?
Operating System
macOS
Operating System Details
No response
Typer Version
0.4.0
Python Version
Python 3.8.10
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions