Typer improperly parsing args from command defined by .callback()
#637
Unanswered
macintacos
asked this question in
Questions
Replies: 2 comments
-
I don't know if it has anything to do with it but, if I understood correctly, the documentation about the option names says that you should put the long name first ("--opt", "-o") instead of ("-o", "--opt"). I also think you might want to use |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have the same problem. When I use a callback decorator, the flags/options has to come before the argument. It doesn't work if it's after. Does not work: $ cli show ARG --json Works: $ cli show --json ARG This makes the experience of the CLI not very user friendly. |
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
-
First Check
Commit to Help
Example Code
Description
The issue is self-contained in the README here: https://github.com/macintacos/repro-typer-improper-args. Copy/pasting below.
Install
Poetry
. Clone the repo and runpoetry install && poetry shell
. Then notice:repro new -o okay lol
successfully runs:...but
repro new okay -o lol
does not:Notice that the other command, not added as a callback, seems to work okay (the command parameters are identical):
For a number of (kinda uninteresting) reasons, I currently have a CLI tool built with the pattern shown in
repro/main.py
andrepo/new.py
.Can someone confirm that this is a bug? Arguments and Options seem to be improperly being parsed when I do this - when I print things out, it seems like everything is going into the
list[str]
, including the-o
option and the option's argument as well.Operating System
macOS
Operating System Details
No response
Typer Version
0.9.0
Python Version
Python 3.10.5
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions