@@ -28,6 +28,7 @@ class OptionHighlighter(RegexHighlighter):
28
28
r"(?P<option>\-\-[\w\-]+)" , # long options like --verbose
29
29
r"(?P<default_option>\[[^\]]+\])" , # anything between [], usually default options
30
30
r"(?P<option_choices>Choices: )" ,
31
+ r"(?P<args_keyword>^[A-Z]+$)" ,
31
32
]
32
33
33
34
@@ -177,6 +178,8 @@ def format_usage(self, ctx: click.Context, formatter: click.formatting.HelpForma
177
178
pieces [index ] = "[options][OPTIONS][/]"
178
179
elif piece == "COMMAND [ARGS]..." :
179
180
pieces [index ] = "[command]COMMAND[/] [args][ARGS][/] ..."
181
+ else :
182
+ pieces [index ] = f"[args_keyword]{ piece } [/]"
180
183
181
184
self .console .print (f"Usage: [path]{ ctx .command_path } [/] { ' ' .join (pieces )} " )
182
185
@@ -202,16 +205,23 @@ def format_epilog(self, ctx: click.Context, formatter: click.formatting.HelpForm
202
205
def format_options (self , ctx , formatter ):
203
206
"""Prints out the options in a table format"""
204
207
205
- # NEXT support binary options --yes/--no
206
- # NEXT SUPPORT color for IDENTIFIER and such
207
208
options_table = Table (highlight = True , box = box .SQUARE , show_header = False )
208
209
209
210
for param in self .get_params (ctx ):
211
+ # useful for showing whats in a param
212
+ # print(param.to_info_dict())
213
+
214
+ # Set Arguments to all uppercase
215
+ if param .param_type_name == 'argument' :
216
+ param .opts [0 ] = param .opts [0 ].upper ()
217
+
218
+ # This option has a short (-v) and long (--verbose) options
210
219
if len (param .opts ) == 2 :
211
220
opt1 = self .highlighter (param .opts [1 ])
212
221
opt2 = self .highlighter (param .opts [0 ])
213
222
else :
214
223
opt2 = self .highlighter (param .opts [0 ])
224
+ # Needs to be the Text() type because rich.Text doesn't mesh with string
215
225
opt1 = Text ("" )
216
226
217
227
# Ensures the short option is always in opt1.
@@ -221,19 +231,20 @@ def format_options(self, ctx, formatter):
221
231
if param .metavar :
222
232
opt2 += Text (f" { param .metavar } " , style = "bold yellow" )
223
233
224
- options = Text (" " .join (reversed (param .opts )))
234
+ # secondary_opts are usually for flags --enable/--disable
235
+ if len (param .secondary_opts ) == 1 :
236
+ opt2 += Text ("|" ) + self .highlighter (param .secondary_opts [0 ])
237
+
225
238
help_record = param .get_help_record (ctx )
226
239
help_message = ""
227
240
if help_record :
228
- help_message = param .get_help_record (ctx )[- 1 ]
241
+ help_message = Text ( param .get_help_record (ctx )[- 1 ])
229
242
230
243
# Add Click choices to help message
231
244
if isinstance (param .type , click .Choice ):
232
245
choices = ", " .join (param .type .choices )
233
246
help_message += f" Choices: { choices } "
234
247
235
- if param .metavar :
236
- options += f" { param .metavar } "
237
248
options_table .add_row (opt1 , opt2 , self .highlighter (help_message ))
238
249
239
250
self .console .print (options_table )
0 commit comments