11
11
from rich .align import Align
12
12
from rich .console import Console
13
13
from rich .table import Table
14
+ from rich .theme import Theme
14
15
15
16
from linodecli .output .output_handler import OutputMode
16
17
17
18
OUTPUT_OVERRIDES = {}
18
19
20
+ REPLICA_STATUS_THEME = {
21
+ "available" : "bright_green" ,
22
+ "creating" : "bright_yellow" ,
23
+ "pending" : "yellow" ,
24
+ "pending replication" : "yellow" ,
25
+ "pending deletion" : "red" ,
26
+ "replicating" : "bright_yellow" ,
27
+ }
28
+
19
29
20
30
def output_override (command : str , action : str , output_mode : OutputMode ):
21
31
"""
@@ -157,7 +167,12 @@ def build_replicas_output(replicas: List) -> Table:
157
167
for replica in replicas :
158
168
row = []
159
169
for h in replicas_headers :
160
- row .append (Align (str (replica [h ]), align = "left" ))
170
+ if h == "status" and replica [h ] in REPLICA_STATUS_THEME :
171
+ row .append (
172
+ Align (str (replica [h ]), align = "left" , style = replica [h ])
173
+ )
174
+ else :
175
+ row .append (Align (str (replica [h ]), align = "left" ))
161
176
replicas_output .add_row (* row )
162
177
163
178
return replicas_output
@@ -167,24 +182,27 @@ def image_replicate_output(json_data) -> bool:
167
182
"""
168
183
Parse and format the image replicate output table.
169
184
"""
185
+ console = Console (theme = Theme (REPLICA_STATUS_THEME ))
186
+
170
187
output = Table (
171
188
header_style = "bold" ,
172
189
show_lines = True ,
173
190
)
174
191
175
192
row = []
176
- for header in json_data .keys ():
177
- if header == "regions" and len (json_data [header ]) > 0 :
178
- # leverage `replicas` in output for readability
179
- output .add_column ("replicas" , justify = "center" )
180
- row .append (build_replicas_output (json_data [header ]))
181
- elif json_data [header ] is not None :
182
- output .add_column (header , justify = "center" )
183
- row .append (Align (str (json_data [header ]), align = "left" ))
193
+ headers = ["id" , "label" , "status" , "total_size" , "regions" ]
194
+ for header in headers :
195
+ if header in json_data :
196
+ if header == "regions" and len (json_data [header ]) > 0 :
197
+ # leverage `replicas` in output for readability
198
+ output .add_column ("replicas" , justify = "center" )
199
+ row .append (build_replicas_output (json_data [header ]))
200
+ elif json_data [header ] is not None :
201
+ output .add_column (header , justify = "center" )
202
+ row .append (Align (str (json_data [header ]), align = "left" ))
184
203
185
204
output .add_row (* row )
186
205
187
- console = Console ()
188
206
console .print (output )
189
207
190
208
return False
0 commit comments