There's no built-in way to rename an argument. Plus metavar
param probably should change only the type representation of an argument.
#845
Unanswered
vladhaidukkk
asked this question in
Questions
Replies: 2 comments
-
I'm also looking to understand how to do this. I don't like that my arguments use underscores and my options use hyphens. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I ran into this and went looking how parameter names are passed to click. Ended up cooking this temporary (and very dirty) patch 😅 def patch_param_names():
"""Call this before calling your Typer app."""
import typer
def get_params_from_function_patched(func):
params = typer.utils.get_params_from_function(func)
new_params = {}
for name, meta in list(params.items()):
if name.startswith("_") or name.endswith("_"):
stripped = name.strip("_")
new_params[stripped] = typer.models.ParamMeta(
name=stripped, default=meta.default, annotation=meta.annotation
)
else:
new_params[name] = meta
return new_params
typer.main.get_params_from_function = get_params_from_function_patched Edit: my previous version would cause argument reordering |
Beta Was this translation helpful? Give feedback.
0 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.
-
First Check
Commit to Help
Example Code
Description
I need a way to rename the argument from id_ to id in the help message. Additionally, it should be displayed in uppercase in the usage section. I've found a recommendation to use
metavar
for this, but it changes the type representation of the argument and how it's displayed in the usage section, which is not what I need.I'd like to have a
name
parameter for this in theArgument
.Operating System
macOS
Operating System Details
No response
Typer Version
0.12.3
Python Version
3.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions