MultiOption

Contents

MultiOption#

tollan.utils.typer.MultiOption(default: Any = Ellipsis, *param_decls: str, **kwargs: Any) MultiOptionInfo[source]#

Create a multi-argument option for Typer commands.

This function wraps typer.Option() to create options that can accept multiple values in a single invocation. It returns a MultiOptionInfo instance that will be detected by the patched get_click_param function to create an OptionEatAll Click option.

Parameters:
  • default (Any, default=...) – Default value for the option

  • *param_decls (str) – Parameter declarations (e.g., “–files”, “-f”)

  • **kwargs (Any) – All other arguments passed to typer.Option() (help, exists, etc.)

Returns:

Extended OptionInfo with multi-option flag

Return type:

MultiOptionInfo

Examples

>>> from typing import Annotated
>>> from pathlib import Path
>>> import typer
>>> from tollan.utils.typer import MultiOption
>>>
>>> app = typer.Typer()
>>>
>>> @app.command()
... def process(
...     files: Annotated[
...         list[Path] | None,
...         MultiOption(
...             help="Files to process",
...             exists=True,
...             dir_okay=False,
...         ),
...     ] = None,
... ):
...     '''Process multiple files.'''
...     if files:
...         for f in files:
...             typer.echo(f"Processing: {f}")
>>>
>>> # $ python main.py process --files file1.txt file2.txt file3.txt
>>> # Processing: file1.txt
>>> # Processing: file2.txt
>>> # Processing: file3.txt