Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andremoeller opened this issue Jul 6, 2020 · 2 comments
Closed

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

andremoeller opened this issue Jul 6, 2020 · 2 comments
Labels
answered bug Something isn't working

Comments

@andremoeller
Copy link

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.

@andremoeller andremoeller added the bug Something isn't working label Jul 6, 2020
@tiangolo
Copy link
Owner

tiangolo commented Jul 6, 2020

Hey, as Typer is based on Click, you can do the same as with Click: https://click.palletsprojects.com/en/7.x/arguments/#option-like-arguments

You would use it like:

$ python main.py -- arg1 --arg2 val2

('arg1', '--arg2', 'val2')

@github-actions
Copy link

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants