How to add flags to custom commands
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the Typer documentation, with the integrated search.
- [X] I already searched in Google "How to X in Typer" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to Typer but to Click.
Commit to Help
- [X] 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
I suspect there is a partial difference in terminology here, where in common command-line parlance we might say "flags", really in most command documentation, a "flag" is an on-off binary condition (such as --verbose or --no-tlsv1.0) and a type of command-line "option"; Typer continues this tradition.
For the Typer specifics, believe you will find the answers to your woes in the documentation / tutorial in the Commands --> Command CLI Options subsection. This, along with the earlier CLI Options section and some of the later sections like CLI Parameter Types and Multiple Options, should have just about everything there is to know about adding options.
Thank you very much! I will look into these :)
Thanks for the help here @nealian ! 👏 🙇
If that solves the original problem, then you can close this issue @AngryMaciek ✔️