You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question 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 tutorials 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
importtyperfromtyping_extensionsimportAnnotatedapp=typer.Typer()
@app.command(context_settings={"allow_extra_args": True, "ignore_unknown_options": True})defmain(cmd: Annotated[
str,
typer.Argument(
help="Command to invoke",
metavar="COMMAND"
)
],
extra_args: Annotated[
typer.Context,
typer.Argument(
help="Extra arguments passed to COMMAND",
metavar="EXTRA_ARGS..."),
]) ->None:
"""This should use subprocess.run..."""print(f"Invoking {cmd} with: {extra_args.args}")
if__name__=="__main__":
app()
Description
I want to create a wrapper around other command, in such way that all unknown arguments passed to the wrapper are passed to said command. I can do that with the help of context_settings={"allow_extra_args": True, "ignore_unknown_options": True}, as described in the documentation: Using the Context: Configuring the context (see the example code, which is very simplified).
What I'd like to have, in the --help output, some placeholder for those extra arguments in the "Usage:", and have the argument described. For example, the usage for git log is
I have tried using typer.Argument (shown in the example) and type.Option to provide metavar for "Usage:", and help for detailed help output. Neither works; the output looks like this:
Usage: python typer_issue_example.py [OPTIONS] COMMAND
This should use subprocess.run...
Arguments:
COMMAND Command to invoke [required]
Options:
What I would like to see would be:
Usage: python typer_issue_example.py [OPTIONS] COMMAND EXTRA_ARGS...
This should use subprocess.run...
Arguments:
COMMAND Command to invoke [required]
EXTRA_ARGS... Extra arguments passed to COMMAND
Options:
I propose adding typer.Parameter (following the name of similar think in Click) to handle this specific purpose.
Note that this issue is different in goal from issue #454 - there the goal was to implement multiple-valued argument / option. It was resolved with description of how to achieve desired goal in a different way (i.e.., the workaround), rather than the solution to the question as stated.
Operating System
Windows
Operating System Details
Windows 10 Home, version 22H2, build 19045.4651
(the feature request is independent of the operating system)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
I want to create a wrapper around other command, in such way that all unknown arguments passed to the wrapper are passed to said command. I can do that with the help of
context_settings={"allow_extra_args": True, "ignore_unknown_options": True}
, as described in the documentation: Using the Context: Configuring the context (see the example code, which is very simplified).What I'd like to have, in the
--help
output, some placeholder for those extra arguments in the "Usage:", and have the argument described. For example, the usage forgit log
isI have tried using
typer.Argument
(shown in the example) andtype.Option
to providemetavar
for "Usage:", andhelp
for detailed help output. Neither works; the output looks like this:What I would like to see would be:
I propose adding
typer.Parameter
(following the name of similar think in Click) to handle this specific purpose.Note that this issue is different in goal from issue #454 - there the goal was to implement multiple-valued argument / option. It was resolved with description of how to achieve desired goal in a different way (i.e.., the workaround), rather than the solution to the question as stated.
Operating System
Windows
Operating System Details
Windows 10 Home, version 22H2, build 19045.4651
(the feature request is independent of the operating system)
Typer Version
typer 0.12.3
Python Version
Python 3.10.4
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions