3333STYLE_SWITCH = "bold green"
3434STYLE_NEGATIVE_OPTION = "bold magenta"
3535STYLE_NEGATIVE_SWITCH = "bold red"
36- STYLE_METAVAR = "bold yellow"
37- STYLE_METAVAR_SEPARATOR = "dim"
36+ STYLE_TYPES = "bold yellow"
37+ STYLE_TYPES_SEPARATOR = "dim"
3838STYLE_USAGE = "yellow"
3939STYLE_USAGE_COMMAND = "bold"
4040STYLE_DEPRECATED = "red"
@@ -112,7 +112,7 @@ class OptionHighlighter(RegexHighlighter):
112112 highlights = [
113113 r"(^|\W)(?P<switch>\-\w+)(?![a-zA-Z0-9])" ,
114114 r"(^|\W)(?P<option>\-\-[\w\-]+)(?![a-zA-Z0-9])" ,
115- r"(?P<metavar >\<[^\>]+\>)" ,
115+ r"(?P<types >\<[^\>]+\>)" ,
116116 r"(?P<usage>Usage: )" ,
117117 ]
118118
@@ -125,17 +125,17 @@ class NegativeOptionHighlighter(RegexHighlighter):
125125
126126
127127# Highlighter to make [ | ] and <> dim
128- class MetavarHighlighter (RegexHighlighter ):
128+ class TypesHighlighter (RegexHighlighter ):
129129 highlights = [
130- r"^(?P<metavar_sep >(\[|<))" ,
131- r"(?P<metavar_sep >\|)" ,
132- r"(?P<metavar_sep >(\]|>))(\.\.\.)?$" ,
130+ r"^(?P<types_sep >(\[|<))" ,
131+ r"(?P<types_sep >\|)" ,
132+ r"(?P<types_sep >(\]|>))(\.\.\.)?$" ,
133133 ]
134134
135135
136136highlighter = OptionHighlighter ()
137137negative_highlighter = NegativeOptionHighlighter ()
138- metavar_highlighter = MetavarHighlighter ()
138+ types_highlighter = TypesHighlighter ()
139139
140140
141141def _has_ansi_character (text : str ) -> bool :
@@ -150,8 +150,8 @@ def _get_rich_console(stderr: bool = False) -> Console:
150150 "switch" : STYLE_SWITCH ,
151151 "negative_option" : STYLE_NEGATIVE_OPTION ,
152152 "negative_switch" : STYLE_NEGATIVE_SWITCH ,
153- "metavar " : STYLE_METAVAR ,
154- "metavar_sep " : STYLE_METAVAR_SEPARATOR ,
153+ "types " : STYLE_TYPES ,
154+ "types_sep " : STYLE_TYPES_SEPARATOR ,
155155 "usage" : STYLE_USAGE ,
156156 },
157157 ),
@@ -364,31 +364,45 @@ def _print_options_panel(
364364 opt_short_strs = []
365365 secondary_opt_long_strs = []
366366 secondary_opt_short_strs = []
367+
368+ # check whether argument has a metavar name or type set
369+ metavar_name = None
370+ metavar_type = None
371+ metavar_str = param .make_metavar (ctx = ctx )
372+ if isinstance (param , TyperArgument ):
373+ # TODO: revise this legacy behaviour of keeping argument names lowercased for Rich formatting
374+ if param .metavar is None and param .name :
375+ metavar_name = metavar_str .replace (param .name .upper (), param .name )
376+ else :
377+ metavar_name = metavar_str
378+ if isinstance (param , TyperOption ):
379+ metavar_type = metavar_str
380+
367381 for opt_str in param .opts :
368382 if "--" in opt_str :
369383 opt_long_strs .append (opt_str )
384+ elif metavar_name :
385+ opt_short_strs .append (metavar_name )
370386 else :
371387 opt_short_strs .append (opt_str )
372388 for opt_str in param .secondary_opts :
373389 if "--" in opt_str :
374390 secondary_opt_long_strs .append (opt_str )
391+ elif metavar_name : # pragma: no cover
392+ secondary_opt_short_strs .append (metavar_name )
375393 else :
376394 secondary_opt_short_strs .append (opt_str )
377395
378- # Column for a metavar, if we have one
379- metavar = Text (style = STYLE_METAVAR , overflow = "fold" )
380- metavar_str = param .make_metavar (ctx = ctx )
381- # Do it ourselves if this is a positional argument
382- if (
383- isinstance (param , TyperArgument )
384- and param .name
385- and metavar_str == param .name .upper ()
386- ):
387- metavar_str = param .type .name .upper ()
396+ # Column for recording the type
397+ types_data = Text (style = STYLE_TYPES , overflow = "fold" )
388398
389- # Skip booleans and choices (handled above)
390- if metavar_str != "BOOLEAN" :
391- metavar .append (metavar_str )
399+ # Fetch type
400+ if metavar_type and metavar_type != "BOOLEAN" :
401+ types_data .append (metavar_type )
402+ else :
403+ type_str = param .type .name .upper ()
404+ if type_str != "BOOLEAN" :
405+ types_data .append (type_str )
392406
393407 # Range - from
394408 # https://github.com/pallets/click/blob/c63c70dabd3f86ca68678b4f00951f78f52d0270/src/click/core.py#L2698-L2706 # noqa: E501
@@ -400,7 +414,7 @@ def _print_options_panel(
400414 ):
401415 range_str = param .type ._describe_range ()
402416 if range_str :
403- metavar .append (RANGE_STRING .format (range_str ))
417+ types_data .append (RANGE_STRING .format (range_str ))
404418
405419 # Required asterisk
406420 required : str | Text = ""
@@ -414,7 +428,7 @@ def _print_options_panel(
414428 highlighter ("," .join (opt_short_strs )),
415429 negative_highlighter ("," .join (secondary_opt_long_strs )),
416430 negative_highlighter ("," .join (secondary_opt_short_strs )),
417- metavar_highlighter ( metavar ),
431+ types_highlighter ( types_data ),
418432 _get_parameter_help (
419433 param = param ,
420434 ctx = ctx ,
0 commit comments