Double dash "--" to stop options parsing #1191
-
First Check
Commit to Help
Example Code@app.command(name="exec")
def exec_(
ctx: typer.Context,
cmd: Annotated[
str,
typer.Argument(
metavar="COMMAND",
help="Command to execute on the nodes",
show_default=False,
),
],
*,
nodeset: Annotated[
str | None,
typer.Option(
"--nodeset",
"-n",
help="Nodeset the command should be executed for.",
),
] = "all@",
sudo: Annotated[
bool,
typer.Option(
"--sudo",
"-s",
help="Execute the command with sudo",
),
] = False,
) -> None:
"""Execute a command on a list of nodes."""DescriptionIs it possible to stop options parsing with a double dash like the GNU extension of getops? For instance, I'd like typer to not process all the arguments after the double dash as options but as a simple str. As a workaround I can wrap the command into quotes but that's kind of annoying. Operating SystemLinux Operating System DetailsI use archlinux btw. Typer Version0.15.2 Python VersionPython 3.12.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Sep 15, 2025
Replies: 1 comment
-
|
It's not documented, but yes, it works this way: import typer
app = typer.Typer()
@app.command()
def my_command(
arg1: str,
opt1: str = "123",
):
typer.echo(f"{arg1=}, {opt1=}")
if __name__ == "__main__":
app()Try it: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not documented, but yes, it works this way:
Try it: