-
First Check
Commit to Help
Example Codeimport typer
app = typer.Typer()
@app.callback()
def main():
"""Main program help text."""
pass
@app.command()
def foo():
"""foo command help text."""
typer.echo("Executed foo.")
if __name__ == "__main__":
app() DescriptionNot sure if this should be considered a bug or enhancement, since this was an undocumented change that could potentially be considered a regression.
I'm fine with the status code change—it does seem to me like an improvement that it has an error code. Thank you for this change. (Though it would be nice for this to be documented in the change log.) However, I think it would be useful to also directly print the help text without requiring users to make another invocation with This appears to be only a typer change, and not a click change, as typer 0.4.0 behaves the same with way both click 8.0.1 and click 7.1.2. typer 0.4.0; click 8.0.1
typer 0.4.0; click 7.1.2
typer 0.3.2; click 7.1.2
Operating SystemmacOS Operating System DetailsNo response Typer Version0.4.0 Python Version3.8.10 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments
-
I am facing the same bug. It is very annoying. Have to stick to 0.3.2 due to this. Took 5 hours of lazy exploration to find out what's going on. @tiangolo - could you kindly comment if this is an expected change in functionality, or a bug og 0.4.0? If it's expected, is there any chance to get the old functionality back? :) Thanks! |
Beta Was this translation helpful? Give feedback.
-
You can use the cli = typer.Typer(no_args_is_help=True) |
Beta Was this translation helpful? Give feedback.
-
Aha, the |
Beta Was this translation helpful? Give feedback.
-
I do think that help strings, especially if not directly invoked with |
Beta Was this translation helpful? Give feedback.
-
Is there a way to set
It would be good if there is a way to set it one time globally. I like being able to see the help text and command list without having to type But there is an issue where zero argument commands don't get executed so maybe defaulting no_args_is_help to False is by design... |
Beta Was this translation helpful? Give feedback.
-
I am facing the same issue described by @jayqi, I have the following app: app = typer.Typer()
@app.command()
def main(
config_file: Optional[Path] = typer.Option(None),
metrics: Optional[MetricsOptions] = typer.Option(None, help=""),
input_file: Optional[Path] = typer.Option(
None,
exists=True,
file_okay=True
),
source: Optional[str] = typer.Option(None),
fetch: Optional[str] = typer.Option(None)
):
if __name__ == "__main__":
app() If I run the app without arguments (pipenv run python ./omnim/src/cli/app.py), I get the following:
Such behavior is kinda expected, as I have a argument that is a file and it must exists(based on the configuration of the app), therefore, if I update the type app to the following:
I would expect that to show up the help message, but this is not what is happening, I still get the error about the file. I tried different approaches but it seems none is working, any considerations why? The code is available at https://github.com/shadowman/omni-metric |
Beta Was this translation helpful? Give feedback.
-
@marabesi I suspect that your error may be a different problem. I think it's coming from |
Beta Was this translation helpful? Give feedback.
-
thanks for the heads up @jayqi |
Beta Was this translation helpful? Give feedback.
-
Could we change the default of |
Beta Was this translation helpful? Give feedback.
-
Maybe we should add |
Beta Was this translation helpful? Give feedback.
-
These should be the default args in my opinion: context_settings={"help_option_names": ["-h", "--help"]},
no_args_is_help=True, |
Beta Was this translation helpful? Give feedback.
-
+1 for the regression behavior, and vote on the default True behavior for |
Beta Was this translation helpful? Give feedback.
-
Thanks all for the discussion here! This was documented here: #751 The new docs are here: https://typer.tiangolo.com/tutorial/commands/#show-the-help-message-if-no-command-is-given |
Beta Was this translation helpful? Give feedback.
Thanks all for the discussion here! This was documented here: #751
The new docs are here: https://typer.tiangolo.com/tutorial/commands/#show-the-help-message-if-no-command-is-given