@@ -28,6 +28,7 @@ class OptionHighlighter(RegexHighlighter):
2828 r"(?P<option>\-\-[\w\-]+)" , # long options like --verbose
2929 r"(?P<default_option>\[[^\]]+\])" , # anything between [], usually default options
3030 r"(?P<option_choices>Choices: )" ,
31+ r"(?P<args_keyword>^[A-Z]+$)" ,
3132 ]
3233
3334
@@ -177,6 +178,8 @@ def format_usage(self, ctx: click.Context, formatter: click.formatting.HelpForma
177178 pieces [index ] = "[options][OPTIONS][/]"
178179 elif piece == "COMMAND [ARGS]..." :
179180 pieces [index ] = "[command]COMMAND[/] [args][ARGS][/] ..."
181+ else :
182+ pieces [index ] = f"[args_keyword]{ piece } [/]"
180183
181184 self .console .print (f"Usage: [path]{ ctx .command_path } [/] { ' ' .join (pieces )} " )
182185
@@ -202,16 +205,23 @@ def format_epilog(self, ctx: click.Context, formatter: click.formatting.HelpForm
202205 def format_options (self , ctx , formatter ):
203206 """Prints out the options in a table format"""
204207
205- # NEXT support binary options --yes/--no
206- # NEXT SUPPORT color for IDENTIFIER and such
207208 options_table = Table (highlight = True , box = box .SQUARE , show_header = False )
208209
209210 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
210219 if len (param .opts ) == 2 :
211220 opt1 = self .highlighter (param .opts [1 ])
212221 opt2 = self .highlighter (param .opts [0 ])
213222 else :
214223 opt2 = self .highlighter (param .opts [0 ])
224+ # Needs to be the Text() type because rich.Text doesn't mesh with string
215225 opt1 = Text ("" )
216226
217227 # Ensures the short option is always in opt1.
@@ -221,19 +231,20 @@ def format_options(self, ctx, formatter):
221231 if param .metavar :
222232 opt2 += Text (f" { param .metavar } " , style = "bold yellow" )
223233
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+
225238 help_record = param .get_help_record (ctx )
226239 help_message = ""
227240 if help_record :
228- help_message = param .get_help_record (ctx )[- 1 ]
241+ help_message = Text ( param .get_help_record (ctx )[- 1 ])
229242
230243 # Add Click choices to help message
231244 if isinstance (param .type , click .Choice ):
232245 choices = ", " .join (param .type .choices )
233246 help_message += f" Choices: { choices } "
234247
235- if param .metavar :
236- options += f" { param .metavar } "
237248 options_table .add_row (opt1 , opt2 , self .highlighter (help_message ))
238249
239250 self .console .print (options_table )
0 commit comments