Skip to content

How to input an iterable as a required command-line option when prompted? #349

Description

@br-follow

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import typer

app = typer.Typer()

@app.command()
def set_roles(
    single: str = typer.Option(..., prompt=True),
    multiple: list[str] = typer.Option(None, prompt=True),
):
    typer.echo(f"{single}")
    typer.echo(f"{multiple}")


if __name__ == "__main__":
    app()

Description

When I run the example without passing any arguments, I cannot pass multiple arguments to the prompt for multiple that satisfies the script. How must I format these at the prompt?

Example:

> python example.py
Single: one
Multple: one, two
Error: Value must be an iterable.
Multple: one two
Error: Value must be an iterable.
Multple: "one" "tow"
Error: Value must be an iterable.
Multple: "one,two"
Error: Value must be an iterable.
Multple: one
Error: Value must be an iterable.
Multple: one
Error: Value must be an iterable.
Multple: "one"
Error: Value must be an iterable.
Multple: [one, two]
Error: Value must be an iterable.
Multple: ["one", "two"]
Error: Value must be an iterable.
Multple: "['one','two']
Error: Value must be an iterable.

Operating System

macOS

Operating System Details

No response

Typer Version

0.4.0

Python Version

Python 3.10.1

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion or problem

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions