Replies: 1 comment
-
You can achieve it using a Solution: def parse_checks(checks: str) -> list[Checks]:
check_objs = []
for check in checks.split(","):
try:
check_obj = Checks(check)
except ValueError:
raise typer.BadParameter(f"{check} should be a valid check.")
check_objs.append(check_obj)
return check_objs
def flatten_checks(
ctx: typer.Context, param: typer.CallbackParam, checks: list[list[Checks]]
) -> list[Checks]:
return [check for subchecks in checks for check in subchecks]
@app.command()
def main(
checks: typing.Annotated[
list[list],
typer.Option(
metavar='CHECK,CHECK,...',
case_sensitive=False,
show_default=True,
help='Checks to execute.',
parser=parse_checks,
callback=flatten_checks,
),
] = list(Checks),
):
typer.echo(f"Selected checks: {checks}") Then it works as expected:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
What works:
What does not work:
How can I create an option which I can specify multiple times and each single occurrence splits the given string at a given separator (in this case the comma
,
character) and in the end I have the list of all given values?Operating System
Linux, Windows
Operating System Details
No response
Typer Version
0.15.2
Python Version
3.13
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions