Skip to content

[BUG] - Arguments with leading hyphens in the name: escaping? #134

@andremoeller

Description

@andremoeller

Describe the bug

I expect that my users will give my app optional arguments do contain leading double hyphens like --input. But I cannot parse optional arguments that have a single ("-") or double ("--") before the rest of the word, since such an argument does not exist.

To Reproduce

Steps to reproduce the behavior with a minimum self-contained file.

Replace each part with your own scenario:

  • Create a file main.py with:
import typer


app = typer.Typer()


@app.command()
def goodbye(app_args: Optional[List[str]] = typer.Argument(None)):
    print(app_args)


if __name__ == "__main__":
    app()
  • Call it with:
python main.py arg1, --arg2, val2
  • It outputs:
no such option: --arg2
  • But I expected it to output:
('arg1,', '--arg2,', 'val2')

Expected behavior

I wanted to retain arguments with single- or double-hypens. I could find no way to escape them and interpret them literally. I expect optional arguments that do contain leading double hyphems like --input.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment

  • OS: [e.g. Linux / Windows / macOS] Mac OS
  • Typer Version [e.g. 0.3.0], get it with: 0.3.0
python -c "import typer; print(typer.__version__)"
  • Python version, get it with:
python --version 3.7.3

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    answeredbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions