Allow --help even if callback has required options / arguments
#1589
-
First Check
Commit to Help
Example Codeimport typer
app = typer.Typer()
@app.command('cmd')
def cmd():
pass
@app.callback()
def main(var: str = typer.Option(...)):
pass
if __name__ == '__main__':
app()DescriptionIf the callback has a required option, running a command under this callback with the code.py --help # works
code.py cmd --help # missing option '--var'Here's why I think this behavior is unintended: @app.callback()
def main(var: str):
passNow both invocations provide the help prompt: code.py --help # works
code.py cmd --help # worksWanted SolutionI would like for typer to print out the usage when passing Wanted Codeimport typer
app = typer.Typer()
@app.command('cmd')
def cmd():
pass
@app.callback()
def main(var: str = typer.Option(...)):
pass
if __name__ == '__main__':
app()AlternativesNo response Operating SystemmacOS Operating System DetailsNo response Typer Version0.3.2 Python Version3.8.9 Additional ContextAfter 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 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
I guess this is intended behavior, but I'm not sure. (...)
@app.callback()
def main(var: str = typer.Option(None)):
pass
(...)Will generate this output foo@bar issue373 % python3 main.py cmd --help
Usage: main.py cmd [OPTIONS]
Options:
--help Show this message and exit.BUT this also indicates another issue: Now users are not aware of the --var option 🤔 |
Beta Was this translation helpful? Give feedback.
-
|
Any news on this very "problem" ? |
Beta Was this translation helpful? Give feedback.
-
|
I'm pretty sure this is a problem in |
Beta Was this translation helpful? Give feedback.
I'm pretty sure this is a problem in
click(and sotyperjust inherits it). See pallets/click#295