1111import click
1212
1313from rich import box
14- from rich .console import Console
1514from rich .highlighter import RegexHighlighter
1615from rich .table import Table
1716from rich .text import Text
18- from rich .theme import Theme
1917
2018from SoftLayer .CLI import environment
19+ from SoftLayer import utils
2120
2221
2322class OptionHighlighter (RegexHighlighter ):
@@ -30,29 +29,19 @@ class OptionHighlighter(RegexHighlighter):
3029 ]
3130
3231
33- # Colors defined in https://rich.readthedocs.io/en/latest/_modules/rich/color.html#ColorType
34- SLCLI_THEME = Theme (
35- {
36- "option" : "bold cyan" ,
37- "switch" : "bold green" ,
38- "default_option" : "light_pink1" ,
39- "option_keyword" : "bold cyan" ,
40- "args_keyword" : "bold green"
41- }
42- )
43-
44-
4532class CommandLoader (click .MultiCommand ):
4633 """Loads module for click."""
4734
4835 def __init__ (self , * path , ** attrs ):
4936 click .MultiCommand .__init__ (self , ** attrs )
5037 self .path = path
51-
5238 self .highlighter = OptionHighlighter ()
53- self .console = Console (
54- theme = SLCLI_THEME
55- )
39+ self .console = utils .console_color_themes (theme = None )
40+
41+ def updated_console_whit_theme (self , theme ):
42+ """Update the console depending on the theme"""
43+ # print(theme)
44+ self .console = utils .console_color_themes (theme )
5645
5746 def list_commands (self , ctx ):
5847 """List all sub-commands."""
@@ -65,7 +54,7 @@ def get_command(self, ctx, cmd_name):
6554 """Get command for click."""
6655 env = ctx .ensure_object (environment .Environment )
6756 env .load ()
68-
57+ self . updated_console_whit_theme ( env . theme )
6958 # Do alias lookup (only available for root commands)
7059 if len (self .path ) == 0 :
7160 cmd_name = env .resolve_alias (cmd_name )
@@ -80,14 +69,17 @@ def get_command(self, ctx, cmd_name):
8069
8170 def format_usage (self , ctx : click .Context , formatter : click .formatting .HelpFormatter ) -> None :
8271 """Formats and colorizes the usage information."""
72+ env = ctx .ensure_object (environment .Environment )
73+ env .load ()
74+ self .updated_console_whit_theme (env .theme )
8375 pieces = self .collect_usage_pieces (ctx )
8476 for index , piece in enumerate (pieces ):
8577 if piece == "[OPTIONS]" :
86- pieces [index ] = "[bold cyan ][OPTIONS][/bold cyan ]"
78+ pieces [index ] = "[options ][OPTIONS][/]"
8779 elif piece == "COMMAND [ARGS]..." :
88- pieces [index ] = "[orange1 ]COMMAND[/orange1 ] [bold cyan ][ARGS][/bold cyan ] ..."
80+ pieces [index ] = "[command ]COMMAND[/] [args ][ARGS][/] ..."
8981
90- self .console .print (f"Usage: [bold red ]{ ctx .command_path } [/bold red ] { ' ' .join (pieces )} " )
82+ self .console .print (f"Usage: [path ]{ ctx .command_path } [/] { ' ' .join (pieces )} " )
9183
9284 def format_help_text (self , ctx : click .Context , formatter : click .formatting .HelpFormatter ) -> None :
9385 """Writes the help text"""
@@ -153,9 +145,9 @@ def format_commands(self, ctx, formatter):
153145 if len (commands ):
154146 for subcommand , cmd in commands :
155147 help_text = cmd .get_short_help_str (120 )
156- command_style = Text (f" { subcommand } " , style = "orange1 " )
148+ command_style = Text (f" { subcommand } " , style = "sub_command " )
157149 command_table .add_row (command_style , help_text )
158- self .console .print ("\n [bold orange1 ]Commands:[/]" )
150+ self .console .print ("\n [name_sub_command ]Commands:[/]" )
159151 self .console .print (command_table )
160152
161153
@@ -165,20 +157,25 @@ class SLCommand(click.Command):
165157 def __init__ (self , ** attrs ):
166158 click .Command .__init__ (self , ** attrs )
167159 self .highlighter = OptionHighlighter ()
168- self .console = Console (
169- theme = SLCLI_THEME
170- )
160+ self .console = utils .console_color_themes (theme = None )
161+
162+ def updated_console_whit_theme (self , theme ):
163+ """Update the console depending on the theme"""
164+ self .console = utils .console_color_themes (theme )
171165
172166 def format_usage (self , ctx : click .Context , formatter : click .formatting .HelpFormatter ) -> None :
173167 """Formats and colorizes the usage information."""
168+ env = ctx .ensure_object (environment .Environment )
169+ env .load ()
170+ self .updated_console_whit_theme (env .theme )
174171 pieces = self .collect_usage_pieces (ctx )
175172 for index , piece in enumerate (pieces ):
176173 if piece == "[OPTIONS]" :
177- pieces [index ] = "[bold cyan ][OPTIONS][/bold cyan ]"
174+ pieces [index ] = "[options ][OPTIONS][/]"
178175 elif piece == "COMMAND [ARGS]..." :
179- pieces [index ] = "[orange1 ]COMMAND[/orange1 ] [bold cyan ][ARGS][/bold cyan ] ..."
176+ pieces [index ] = "[command ]COMMAND[/] [args ][ARGS][/] ..."
180177
181- self .console .print (f"Usage: [bold red ]{ ctx .command_path } [/bold red ] { ' ' .join (pieces )} " )
178+ self .console .print (f"Usage: [path ]{ ctx .command_path } [/] { ' ' .join (pieces )} " )
182179
183180 def format_help_text (self , ctx : click .Context , formatter : click .formatting .HelpFormatter ) -> None :
184181 """Writes the help text"""
0 commit comments