77
88from helm_values_manager .errors import ErrorHandler , SchemaError , error_console
99from 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+ )
1116
1217console = Console ()
1318app = typer .Typer ()
@@ -54,33 +59,35 @@ def add_command(
5459 schema = load_schema (schema_path )
5560 if not schema :
5661 ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
57-
62+
5863 console .print ("[bold]Add new value to schema[/bold]\n " )
59-
64+
6065 # Prompt for key
6166 while True :
6267 key = Prompt .ask ("Key (unique identifier)" )
6368 if not key :
6469 error_console .print ("[red]Key cannot be empty[/red]" )
6570 continue
66-
71+
6772 if not validate_key_unique (schema , key ):
6873 error_console .print (f"[red]Key '{ key } ' already exists in schema[/red]" )
6974 continue
70-
75+
7176 break
72-
77+
7378 # Prompt for path
7479 while True :
7580 path = Prompt .ask ("Path (dot-separated YAML path)" )
7681 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+ )
7885 continue
7986 break
80-
87+
8188 # Prompt for description
8289 description = Prompt .ask ("Description" )
83-
90+
8491 # Prompt for type
8592 type_choices = ["string" , "number" , "boolean" , "array" , "object" ]
8693 console .print ("\n Type options: " + ", " .join (type_choices ))
@@ -89,10 +96,10 @@ def add_command(
8996 if value_type in type_choices :
9097 break
9198 error_console .print (f"[red]Invalid type. Choose from: { ', ' .join (type_choices )} [/red]" )
92-
99+
93100 # Prompt for required
94101 required = Confirm .ask ("Required?" , default = True )
95-
102+
96103 # Prompt for default value
97104 default = None
98105 if Confirm .ask ("Set default value?" , default = False ):
@@ -103,10 +110,10 @@ def add_command(
103110 break
104111 except SchemaError as e :
105112 error_console .print (f"[red]{ e } [/red]" )
106-
113+
107114 # Prompt for sensitive
108115 sensitive = Confirm .ask ("Sensitive value?" , default = False )
109-
116+
110117 # Create and add the new value
111118 new_value = SchemaValue (
112119 key = key ,
@@ -117,12 +124,12 @@ def add_command(
117124 default = default ,
118125 sensitive = sensitive ,
119126 )
120-
127+
121128 schema .values .append (new_value )
122-
129+
123130 # Save the updated schema
124131 save_schema (schema , schema_path )
125-
132+
126133 console .print (f"\n [green]✓[/green] Added '{ key } ' to schema" )
127134 console .print (f" Path: { path } " )
128135 console .print (f" Type: { value_type } " )
@@ -140,13 +147,13 @@ def list_command(
140147 schema = load_schema (schema_path )
141148 if not schema :
142149 ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
143-
150+
144151 if not schema .values :
145152 console .print ("No values defined in schema." )
146153 return
147-
154+
148155 console .print ("[bold]Schema Values:[/bold]\n " )
149-
156+
150157 for value in schema .values :
151158 status = "[green]●[/green]" if value .required else "[yellow]○[/yellow]"
152159 sensitive = " 🔒" if value .sensitive else ""
@@ -168,20 +175,22 @@ def get_command(
168175 schema = load_schema (schema_path )
169176 if not schema :
170177 ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
171-
178+
172179 # Find the value
173180 value = next ((v for v in schema .values if v .key == key ), None )
174181 if not value :
175182 ErrorHandler .print_error ("schema" , f"Value with key '{ key } ' not found" )
176-
183+
177184 # Display details
178185 console .print (f"\n [bold]{ value .key } [/bold]" )
179186 console .print (f"Path: { value .path } " )
180187 console .print (f"Type: { value .type } " )
181188 console .print (f"Description: { value .description } " )
182189 console .print (f"Required: { value .required } " )
183190 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+ )
185194 console .print (f"Sensitive: { value .sensitive } " )
186195
187196
@@ -194,28 +203,30 @@ def update_command(
194203 schema = load_schema (schema_path )
195204 if not schema :
196205 ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
197-
206+
198207 # Find the value
199208 value_index = next ((i for i , v in enumerate (schema .values ) if v .key == key ), None )
200209 if value_index is None :
201210 ErrorHandler .print_error ("schema" , f"Value with key '{ key } ' not found" )
202-
211+
203212 value = schema .values [value_index ]
204213 console .print (f"[bold]Updating '{ key } '[/bold]\n " )
205214 console .print ("Press Enter to keep current value\n " )
206-
215+
207216 # Update path
208217 new_path = Prompt .ask (f"Path [{ value .path } ]" , default = value .path )
209218 if new_path != value .path :
210219 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+ )
212223 new_path = Prompt .ask (f"Path [{ value .path } ]" , default = value .path )
213224 value .path = new_path
214-
225+
215226 # Update description
216227 new_description = Prompt .ask (f"Description [{ value .description } ]" , default = value .description )
217228 value .description = new_description
218-
229+
219230 # Update type
220231 type_choices = ["string" , "number" , "boolean" , "array" , "object" ]
221232 console .print (f"\n Type options: { ', ' .join (type_choices )} " )
@@ -229,10 +240,10 @@ def update_command(
229240 if value .default is not None :
230241 if Confirm .ask ("Type changed. Clear default value?" , default = True ):
231242 value .default = None
232-
243+
233244 # Update required
234245 value .required = Confirm .ask ("Required?" , default = value .required )
235-
246+
236247 # Update default
237248 if value .default is None :
238249 if Confirm .ask ("Set default value?" , default = False ):
@@ -244,18 +255,20 @@ def update_command(
244255 except SchemaError as e :
245256 error_console .print (f"[red]{ e } [/red]" )
246257 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+ )
248261 console .print (f"\n Current default value: { default_display } " )
249-
262+
250263 # Offer options for existing default
251264 console .print ("Options:" )
252265 console .print ("1. Keep current default" )
253266 console .print ("2. Update default value" )
254267 console .print ("3. Remove default value" )
255-
268+
256269 while True :
257270 choice = Prompt .ask ("Choose option" , choices = ["1" , "2" , "3" ], default = "1" )
258-
271+
259272 if choice == "1" :
260273 # Keep current default
261274 break
@@ -272,20 +285,22 @@ def update_command(
272285 elif choice == "3" :
273286 # Remove default value
274287 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+ )
276291 if not Confirm .ask ("Continue removing default?" , default = False ):
277292 continue
278-
293+
279294 value .default = None
280295 console .print ("[green]✓[/green] Default value removed" )
281296 break
282-
297+
283298 # Update sensitive
284299 value .sensitive = Confirm .ask ("Sensitive value?" , default = value .sensitive )
285-
300+
286301 # Save the updated schema
287302 save_schema (schema , schema_path )
288-
303+
289304 console .print (f"\n [green]✓[/green] Updated '{ key } ' in schema" )
290305
291306
@@ -299,29 +314,29 @@ def remove_command(
299314 schema = load_schema (schema_path )
300315 if not schema :
301316 ErrorHandler .print_error ("schema" , "No schema.json found. Run 'init' first." )
302-
317+
303318 # Find the value
304319 value_index = next ((i for i , v in enumerate (schema .values ) if v .key == key ), None )
305320 if value_index is None :
306321 ErrorHandler .print_error ("schema" , f"Value with key '{ key } ' not found" )
307-
322+
308323 value = schema .values [value_index ]
309-
324+
310325 # Confirm removal
311326 if not force :
312327 console .print ("\n [bold]Value to remove:[/bold]" )
313328 console .print (f"Key: { value .key } " )
314329 console .print (f"Path: { value .path } " )
315330 console .print (f"Description: { value .description } " )
316-
331+
317332 if not Confirm .ask ("\n Remove this value?" , default = False ):
318333 console .print ("Cancelled" )
319334 raise typer .Exit (0 )
320-
335+
321336 # Remove the value
322337 schema .values .pop (value_index )
323-
338+
324339 # Save the updated schema
325340 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