-
-
Notifications
You must be signed in to change notification settings - Fork 861
Description
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
import typer
app = typer.Typer()
@app.command('cmd')
def cmd():
pass
@app.callback()
def main(var: str = typer.Option(...)):
pass
if __name__ == '__main__':
app()Description
If the callback has a required option, running a command under this callback with the --help option will give a "missing option" error.
code.py --help # works
code.py cmd --help # missing option '--var'Here's why I think this behavior is unintended:
On typer 0.3.2, regular arguments defined in the callback are not required when passing --help to commands under the callback. Let's change the main function to this:
@app.callback()
def main(var: str):
passNow both invocations provide the help prompt:
code.py --help # works
code.py cmd --help # worksWanted Solution
I would like for typer to print out the usage when passing --help when required options are not passed, just like it prints the usage when required arguments are not passed
Wanted Code
import typer
app = typer.Typer()
@app.command('cmd')
def cmd():
pass
@app.callback()
def main(var: str = typer.Option(...)):
pass
if __name__ == '__main__':
app()Alternatives
No response
Operating System
macOS
Operating System Details
No response
Typer Version
0.3.2
Python Version
3.8.9
Additional Context
After filling out the version, I checked the behavior with typer 0.4.0 and both argument and option don't print out the usage when running the subcommand with --help