-
-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove [default: None]
for arguments and required options
#465
Comments
I didn't think about it before, but it seems like an obvious solution to this is to just use |
when using show_default = False, it would be nice if a default added by the programmer [which is sometimes the reason for this] it would be nice if there is something that looks like a default e.g [default: ....] it would also be coloured grey like the normal default text [or is that too magical] I tried with rich styling but it didn't seem to work but my typer maybe too old 0.7.0... |
Confirming using |
This seems to have regressed in 0.13.0 (works in 0.12.5)? |
I would suggest the following code change to rich_utils.py Lines 288 to 302 in f110845
diff --git a/typer/rich_utils.py b/typer/rich_utils.py
index 7d603da..46e2474 100644
--- a/typer/rich_utils.py
+++ b/typer/rich_utils.py
@@ -285,9 +285,9 @@ def _get_parameter_help(
# Default value
# This uses Typer's specific param._get_default_string
if isinstance(param, (TyperOption, TyperArgument)):
- if param.show_default:
- show_default_is_str = isinstance(param.show_default, str)
- default_value = param._extract_default_help_str(ctx=ctx)
+ default_value = param._extract_default_help_str(ctx=ctx)
+ show_default_is_str = isinstance(param.show_default, str)
+ if show_default_is_str or (default_value is not None and (param.show_default or ctx.show_default)):
default_str = param._get_default_string(
ctx=ctx,
show_default_is_str=show_default_is_str, This would make it align better with other implementations in core.py Lines 351 to 368 in f110845
|
…s installed Fixes fastapi#465 Improves consitency with typer/core.py TyperArgument.get_help_record, which does not print the default value if it is None.
First Check
Commit to Help
Example Code
Description
In order to make the help output less cluttered, it makes sense to hide the
[default: None]
for arguments and required options since a value must always be passed (meaning that the default doesn't really have any use).As an aside, I supposed that the
default
is sometimes used as an "example," so maybe it could make sense to add anexample
param that could be used for this purpose?Wanted Solution
Current help output:
Desired help output:
Wanted Code
# No changes to the way `typer` is used
Alternatives
No response
Operating System
Linux, macOS
Operating System Details
No response
Typer Version
0.6.1
Python Version
Python 3.8.14
Additional Context
Obviously, this is a personal preference. I just feel that it helps to clean up the
--help
output a little bit.The text was updated successfully, but these errors were encountered: