1- import click
2- import types
1+ """
2+ SoftLayer.CLI.command
3+ ~~~~~~~~~~~~~~~~~~~~~
4+ Command interface for the SoftLayer CLI. Basically the Click commands, with fancy help text
5+
6+ :license: MIT, see LICENSE for more details.
7+ """
38import inspect
9+ import types
10+
11+ import click
412
513from rich import box
6- from rich .console import Console , RenderableType
7- from rich .markup import escape
8- from rich .text import Text
14+ from rich .console import Console
915from rich .highlighter import RegexHighlighter
10- from rich .panel import Panel
1116from rich .table import Table
17+ from rich .text import Text
1218from rich .theme import Theme
1319
14-
1520from SoftLayer .CLI import environment
1621
22+
1723class OptionHighlighter (RegexHighlighter ):
24+ """Provides highlighter regex for the Command help"""
1825 highlights = [
19- r"(?P<switch>\-\w)" , # single options like -v
20- r"(?P<option>\-\-[\w\-]+)" , # long options like --verbose
21- r"(?P<default_option>\[[^\]]+\])" , # anything between [], usually default options
26+ r"(?P<switch>\-\w)" , # single options like -v
27+ r"(?P<option>\-\-[\w\-]+)" , # long options like --verbose
28+ r"(?P<default_option>\[[^\]]+\])" , # anything between [], usually default options
2229
2330 ]
2431
25- # Colors defined in https://rich.readthedocs.io/en/latest/_modules/rich/color.html#ColorType
32+
33+ # Colors defined in https://rich.readthedocs.io/en/latest/_modules/rich/color.html#ColorType
2634SLCLI_THEME = Theme (
2735 {
2836 "option" : "bold cyan" ,
@@ -86,7 +94,7 @@ def format_help_text(self, ctx: click.Context, formatter: click.formatting.HelpF
8694 text = self .help if self .help is not None else ""
8795
8896 if self .deprecated :
89- text = _ ( "(Deprecated) {text}" ). format ( text = text )
97+ text = f "(Deprecated) { text } "
9098
9199 if text :
92100 text = inspect .cleandoc (text ).partition ("\f " )[0 ]
@@ -100,7 +108,6 @@ def format_epilog(self, ctx: click.Context, formatter: click.formatting.HelpForm
100108 self .console .print (epilog )
101109 self .format_commands (ctx , formatter )
102110
103-
104111 def format_options (self , ctx , formatter ):
105112 """Prints out the options in a table format"""
106113
@@ -151,17 +158,17 @@ def format_commands(self, ctx, formatter):
151158 self .console .print ("\n [bold orange1]Commands:[/]" )
152159 self .console .print (command_table )
153160
161+
154162class SLCommand (click .Command ):
155163 """Overloads click.Command to control how the help message is formatted."""
156164
157- def __init__ (self , * path , * *attrs ):
165+ def __init__ (self , ** attrs ):
158166 click .Command .__init__ (self , ** attrs )
159167 self .highlighter = OptionHighlighter ()
160168 self .console = Console (
161169 theme = SLCLI_THEME
162170 )
163171
164-
165172 def format_usage (self , ctx : click .Context , formatter : click .formatting .HelpFormatter ) -> None :
166173 """Formats and colorizes the usage information."""
167174 pieces = self .collect_usage_pieces (ctx )
@@ -178,7 +185,7 @@ def format_help_text(self, ctx: click.Context, formatter: click.formatting.HelpF
178185 text = self .help if self .help is not None else ""
179186
180187 if self .deprecated :
181- text = _ ( "(Deprecated) {text}" ). format ( text = text )
188+ text = f "(Deprecated) { text } "
182189
183190 if text :
184191 text = inspect .cleandoc (text )
@@ -195,8 +202,8 @@ def format_epilog(self, ctx: click.Context, formatter: click.formatting.HelpForm
195202 def format_options (self , ctx , formatter ):
196203 """Prints out the options in a table format"""
197204
198- ## TODO support binary options --yes/--no
199- ## SUPPORT color for IDENTIFIER and such
205+ # NEXT support binary options --yes/--no
206+ # NEXT SUPPORT color for IDENTIFIER and such
200207 options_table = Table (highlight = True , box = box .SQUARE , show_header = False )
201208
202209 for param in self .get_params (ctx ):
0 commit comments