Replies: 2 comments 4 replies
-
I've implemented this feature in #355, if anyone can think of a workaround please let me know. It is very challenging to customize the output of help since the click classes are obscured. |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can achieve this with f-string ( import typer
def generate():
return "User!"
def main(
name: str = typer.Argument(
default=generate, show_default=f"{generate()} (generated)"
),
):
typer.echo(f"Hello {name}")
if __name__ == "__main__":
typer.run(main) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Running this produces
And help produces
However, I'd like to be able to show the default value still. In my use-case, the default is not a constant, but it is deterministic based on user's environment.
I can use
show_default
to set a string e.g.typer.Argument(default=generate, show_default="test")
but since this cannot be a callable I cannot make it match the value returned bygenerate
.Wanted Solution
You should be able to override help for dynamic defaults to be similarly dynamic.
Wanted Code
Alternatives
I've explored using
show_default
to provide a string value directly, but it must be a callable to be resolved at command call time rather than at module import time.Another alternative is to display the dynamic default value instead of
"(dynamic)"
by default. Encourage the user to useshow_default="(dynamic)"
if it's random. This is a breaking change and does not allow for appending additional information to the generated default.Operating System
macOS
Operating System Details
No response
Typer Version
0.4.0
Python Version
3.8
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions