Skip to content

How to add flags to custom commands #457

@AngryMaciek

Description

@AngryMaciek

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue 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 tutorial 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

@app.command(
    name="foo",
    help="bar",
)
def command1(path: str) -> None:  # noqa: D401
    """
    Text

    Args:
        path: my favourite path
    """
    # some code here

Description

I am new to Typer but I cannot really find the info I need in the docs nor Google/SO...
I am trying to add flags to my app with typer commands. I would like to have:

myApp command1 --flag1 value1 --flag2 value2

Is it possible to modify the code I posted above so that the commands accepts additional named parameters?

Operating System

Linux

Operating System Details

Ubuntu 20.04

Typer Version

0.4.1

Python Version

Python 3.9.13

Additional Context

I asked the same question on StackOverflow but did not get any response yet:
https://stackoverflow.com/questions/73780139/how-to-add-flags-for-typer-commands-in-python

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions