7
7
8
8
from helm_values_manager .errors import ErrorHandler , SchemaError , error_console
9
9
from helm_values_manager .models import SchemaValue , ValueType
10
- from helm_values_manager .utils import load_schema , save_schema , validate_key_unique , validate_path_format
10
+ from helm_values_manager .utils import (
11
+ load_schema ,
12
+ save_schema ,
13
+ validate_key_unique ,
14
+ validate_path_format ,
15
+ )
11
16
12
17
console = Console ()
13
18
app = typer .Typer ()
@@ -54,33 +59,35 @@ def add_command(
54
59
schema = load_schema (schema_path )
55
60
if not schema :
56
61
ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
57
-
62
+
58
63
console .print ("[bold]Add new value to schema[/bold]\n " )
59
-
64
+
60
65
# Prompt for key
61
66
while True :
62
67
key = Prompt .ask ("Key (unique identifier)" )
63
68
if not key :
64
69
error_console .print ("[red]Key cannot be empty[/red]" )
65
70
continue
66
-
71
+
67
72
if not validate_key_unique (schema , key ):
68
73
error_console .print (f"[red]Key '{ key } ' already exists in schema[/red]" )
69
74
continue
70
-
75
+
71
76
break
72
-
77
+
73
78
# Prompt for path
74
79
while True :
75
80
path = Prompt .ask ("Path (dot-separated YAML path)" )
76
81
if not validate_path_format (path ):
77
- error_console .print ("[red]Invalid path format. Use alphanumeric characters and dots only.[/red]" )
82
+ error_console .print (
83
+ "[red]Invalid path format. Use alphanumeric characters and dots only.[/red]"
84
+ )
78
85
continue
79
86
break
80
-
87
+
81
88
# Prompt for description
82
89
description = Prompt .ask ("Description" )
83
-
90
+
84
91
# Prompt for type
85
92
type_choices = ["string" , "number" , "boolean" , "array" , "object" ]
86
93
console .print ("\n Type options: " + ", " .join (type_choices ))
@@ -89,10 +96,10 @@ def add_command(
89
96
if value_type in type_choices :
90
97
break
91
98
error_console .print (f"[red]Invalid type. Choose from: { ', ' .join (type_choices )} [/red]" )
92
-
99
+
93
100
# Prompt for required
94
101
required = Confirm .ask ("Required?" , default = True )
95
-
102
+
96
103
# Prompt for default value
97
104
default = None
98
105
if Confirm .ask ("Set default value?" , default = False ):
@@ -103,10 +110,10 @@ def add_command(
103
110
break
104
111
except SchemaError as e :
105
112
error_console .print (f"[red]{ e } [/red]" )
106
-
113
+
107
114
# Prompt for sensitive
108
115
sensitive = Confirm .ask ("Sensitive value?" , default = False )
109
-
116
+
110
117
# Create and add the new value
111
118
new_value = SchemaValue (
112
119
key = key ,
@@ -117,12 +124,12 @@ def add_command(
117
124
default = default ,
118
125
sensitive = sensitive ,
119
126
)
120
-
127
+
121
128
schema .values .append (new_value )
122
-
129
+
123
130
# Save the updated schema
124
131
save_schema (schema , schema_path )
125
-
132
+
126
133
console .print (f"\n [green]✓[/green] Added '{ key } ' to schema" )
127
134
console .print (f" Path: { path } " )
128
135
console .print (f" Type: { value_type } " )
@@ -140,13 +147,13 @@ def list_command(
140
147
schema = load_schema (schema_path )
141
148
if not schema :
142
149
ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
143
-
150
+
144
151
if not schema .values :
145
152
console .print ("No values defined in schema." )
146
153
return
147
-
154
+
148
155
console .print ("[bold]Schema Values:[/bold]\n " )
149
-
156
+
150
157
for value in schema .values :
151
158
status = "[green]●[/green]" if value .required else "[yellow]○[/yellow]"
152
159
sensitive = " 🔒" if value .sensitive else ""
@@ -168,20 +175,22 @@ def get_command(
168
175
schema = load_schema (schema_path )
169
176
if not schema :
170
177
ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
171
-
178
+
172
179
# Find the value
173
180
value = next ((v for v in schema .values if v .key == key ), None )
174
181
if not value :
175
182
ErrorHandler .print_error ("schema" , f"Value with key '{ key } ' not found" )
176
-
183
+
177
184
# Display details
178
185
console .print (f"\n [bold]{ value .key } [/bold]" )
179
186
console .print (f"Path: { value .path } " )
180
187
console .print (f"Type: { value .type } " )
181
188
console .print (f"Description: { value .description } " )
182
189
console .print (f"Required: { value .required } " )
183
190
if value .default is not None :
184
- console .print (f"Default: { json .dumps (value .default , indent = 2 ) if value .type in ['array' , 'object' ] else value .default } " )
191
+ console .print (
192
+ f"Default: { json .dumps (value .default , indent = 2 ) if value .type in ['array' , 'object' ] else value .default } "
193
+ )
185
194
console .print (f"Sensitive: { value .sensitive } " )
186
195
187
196
@@ -194,28 +203,30 @@ def update_command(
194
203
schema = load_schema (schema_path )
195
204
if not schema :
196
205
ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
197
-
206
+
198
207
# Find the value
199
208
value_index = next ((i for i , v in enumerate (schema .values ) if v .key == key ), None )
200
209
if value_index is None :
201
210
ErrorHandler .print_error ("schema" , f"Value with key '{ key } ' not found" )
202
-
211
+
203
212
value = schema .values [value_index ]
204
213
console .print (f"[bold]Updating '{ key } '[/bold]\n " )
205
214
console .print ("Press Enter to keep current value\n " )
206
-
215
+
207
216
# Update path
208
217
new_path = Prompt .ask (f"Path [{ value .path } ]" , default = value .path )
209
218
if new_path != value .path :
210
219
while not validate_path_format (new_path ):
211
- error_console .print ("[red]Invalid path format. Use alphanumeric characters and dots only.[/red]" )
220
+ error_console .print (
221
+ "[red]Invalid path format. Use alphanumeric characters and dots only.[/red]"
222
+ )
212
223
new_path = Prompt .ask (f"Path [{ value .path } ]" , default = value .path )
213
224
value .path = new_path
214
-
225
+
215
226
# Update description
216
227
new_description = Prompt .ask (f"Description [{ value .description } ]" , default = value .description )
217
228
value .description = new_description
218
-
229
+
219
230
# Update type
220
231
type_choices = ["string" , "number" , "boolean" , "array" , "object" ]
221
232
console .print (f"\n Type options: { ', ' .join (type_choices )} " )
@@ -229,10 +240,10 @@ def update_command(
229
240
if value .default is not None :
230
241
if Confirm .ask ("Type changed. Clear default value?" , default = True ):
231
242
value .default = None
232
-
243
+
233
244
# Update required
234
245
value .required = Confirm .ask ("Required?" , default = value .required )
235
-
246
+
236
247
# Update default
237
248
if value .default is None :
238
249
if Confirm .ask ("Set default value?" , default = False ):
@@ -244,18 +255,20 @@ def update_command(
244
255
except SchemaError as e :
245
256
error_console .print (f"[red]{ e } [/red]" )
246
257
else :
247
- default_display = json .dumps (value .default ) if value .type in ['array' , 'object' ] else str (value .default )
258
+ default_display = (
259
+ json .dumps (value .default ) if value .type in ["array" , "object" ] else str (value .default )
260
+ )
248
261
console .print (f"\n Current default value: { default_display } " )
249
-
262
+
250
263
# Offer options for existing default
251
264
console .print ("Options:" )
252
265
console .print ("1. Keep current default" )
253
266
console .print ("2. Update default value" )
254
267
console .print ("3. Remove default value" )
255
-
268
+
256
269
while True :
257
270
choice = Prompt .ask ("Choose option" , choices = ["1" , "2" , "3" ], default = "1" )
258
-
271
+
259
272
if choice == "1" :
260
273
# Keep current default
261
274
break
@@ -272,20 +285,22 @@ def update_command(
272
285
elif choice == "3" :
273
286
# Remove default value
274
287
if value .required :
275
- ErrorHandler .print_warning ("This field is required but will have no default value" )
288
+ ErrorHandler .print_warning (
289
+ "This field is required but will have no default value"
290
+ )
276
291
if not Confirm .ask ("Continue removing default?" , default = False ):
277
292
continue
278
-
293
+
279
294
value .default = None
280
295
console .print ("[green]✓[/green] Default value removed" )
281
296
break
282
-
297
+
283
298
# Update sensitive
284
299
value .sensitive = Confirm .ask ("Sensitive value?" , default = value .sensitive )
285
-
300
+
286
301
# Save the updated schema
287
302
save_schema (schema , schema_path )
288
-
303
+
289
304
console .print (f"\n [green]✓[/green] Updated '{ key } ' in schema" )
290
305
291
306
@@ -299,29 +314,29 @@ def remove_command(
299
314
schema = load_schema (schema_path )
300
315
if not schema :
301
316
ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
302
-
317
+
303
318
# Find the value
304
319
value_index = next ((i for i , v in enumerate (schema .values ) if v .key == key ), None )
305
320
if value_index is None :
306
321
ErrorHandler .print_error ("schema" , f"Value with key '{ key } ' not found" )
307
-
322
+
308
323
value = schema .values [value_index ]
309
-
324
+
310
325
# Confirm removal
311
326
if not force :
312
327
console .print ("\n [bold]Value to remove:[/bold]" )
313
328
console .print (f"Key: { value .key } " )
314
329
console .print (f"Path: { value .path } " )
315
330
console .print (f"Description: { value .description } " )
316
-
331
+
317
332
if not Confirm .ask ("\n Remove this value?" , default = False ):
318
333
console .print ("Cancelled" )
319
334
raise typer .Exit (0 )
320
-
335
+
321
336
# Remove the value
322
337
schema .values .pop (value_index )
323
-
338
+
324
339
# Save the updated schema
325
340
save_schema (schema , schema_path )
326
-
327
- console .print (f"\n [green]✓[/green] Removed '{ key } ' from schema" )
341
+
342
+ console .print (f"\n [green]✓[/green] Removed '{ key } ' from schema" )
0 commit comments