@@ -137,6 +137,44 @@ def add_codegen_args(parser: argparse.ArgumentParser):
137137 help = "Case style for JSON tag names in Go" ,
138138 )
139139
140+ # Python-specific options
141+ python_group = parser .add_argument_group ("Python-specific options" )
142+ python_group .add_argument (
143+ "--python-style" ,
144+ choices = ["dataclass" , "pydantic" , "typeddict" ],
145+ help = "Python code style (default: dataclass)" ,
146+ )
147+
148+ python_group .add_argument (
149+ "--no-slots" ,
150+ action = "store_true" ,
151+ help = "Don't use __slots__ in dataclasses" ,
152+ )
153+
154+ python_group .add_argument (
155+ "--frozen" ,
156+ action = "store_true" ,
157+ help = "Make dataclasses frozen (immutable)" ,
158+ )
159+
160+ python_group .add_argument (
161+ "--kw-only" ,
162+ action = "store_true" ,
163+ help = "Make dataclass fields keyword-only" ,
164+ )
165+
166+ python_group .add_argument (
167+ "--no-pydantic-field" ,
168+ action = "store_true" ,
169+ help = "Don't use Field() in Pydantic models" ,
170+ )
171+
172+ python_group .add_argument (
173+ "--pydantic-forbid-extra" ,
174+ action = "store_true" ,
175+ help = "Forbid extra fields in Pydantic models" ,
176+ )
177+
140178
141179def handle_codegen_command (args : argparse .Namespace , json_data = None ) -> int :
142180 """
@@ -203,7 +241,7 @@ def _list_languages() -> int:
203241 table .add_column ("Language" , style = "bold green" , no_wrap = True )
204242 table .add_column ("Extension" , style = "cyan" )
205243 table .add_column ("Generator Class" , style = "dim" )
206- table .add_column ("Aliases" , style = "gold1 " )
244+ table .add_column ("Aliases" , style = "gold1" )
207245
208246 for lang_name , info in sorted (language_info .items ()):
209247 aliases = (
@@ -222,7 +260,8 @@ def _list_languages() -> int:
222260 console .print (
223261 Panel (
224262 "[bold]Usage:[/bold] json_explorer [dim]input.json[/dim] --generate [cyan]LANGUAGE[/cyan]\n "
225- "[bold]Info:[/bold] json_explorer --language-info [cyan]LANGUAGE[/cyan]" ,
263+ "[bold]Info:[/bold] json_explorer --language-info [cyan]LANGUAGE[/cyan]\n "
264+ "[bold]Python:[/bold] json_explorer [dim]input.json[/dim] --generate [cyan]python[/cyan] --python-style [yellow]dataclass[/yellow]" ,
226265 title = "💡 Quick Start" ,
227266 border_style = "blue" ,
228267 )
@@ -263,59 +302,54 @@ def _show_language_info(language: str) -> int:
263302 )
264303 )
265304
266- # Try to get configuration details
267- try :
268- generator = get_generator (language )
269-
270- # Create configuration table
271- config_table = Table (
272- title = "⚙️ Default Configuration" ,
273- box = box .SIMPLE ,
274- show_header = True ,
275- header_style = "bold cyan" ,
276- )
305+ # Show language-specific examples
306+ if language == "python" :
307+ _show_python_examples ()
308+ elif language == "go" :
309+ _show_go_examples ()
277310
278- config_table .add_column ("Setting" , style = "bold" )
279- config_table .add_column ("Value" , style = "green" )
311+ return 0
280312
281- config_table .add_row ("Package Name" , str (generator .config .package_name ))
282- config_table .add_row ("Indent Size" , str (generator .config .indent_size ))
283- config_table .add_row (
284- "Generate JSON Tags" , str (generator .config .generate_json_tags )
285- )
286- config_table .add_row ("Add Comments" , str (generator .config .add_comments ))
287- config_table .add_row (
288- "JSON Tag Omitempty" , str (generator .config .json_tag_omitempty )
289- )
313+ except Exception as e :
314+ console .print (f"[red]❌ Error getting language info:[/red] { e } " )
315+ return 1
290316
291- console .print ()
292- console .print (config_table )
293317
294- except Exception :
295- console . print (
296- " \n [yellow]⚠️ Could not retrieve configuration details[/yellow]"
297- )
318+ def _show_python_examples () :
319+ """Show Python-specific CLI examples."""
320+ examples_text = """Generate dataclass:
321+ [cyan]json_explorer data.json --generate python --python-style dataclass[/cyan]
298322
299- # Add examples panel
300- examples_text = f"""Generate basic structure:
301- [cyan]json_explorer data.json --generate { language } [/cyan]
323+ Generate Pydantic model:
324+ [cyan]json_explorer data.json --generate python --python-style pydantic[/cyan]
302325
303- Generate to file :
304- [cyan]json_explorer data.json --generate { language } --output output { info [ 'file_extension' ] } [/cyan]
326+ Generate TypedDict :
327+ [cyan]json_explorer data.json --generate python --python-style typeddict [/cyan]
305328
306- Custom package name :
307- [cyan]json_explorer data.json --generate { language } --package-name mypackage [/cyan]"""
329+ Frozen dataclass with slots :
330+ [cyan]json_explorer data.json --generate python --frozen --python-style dataclass [/cyan]"""
308331
309- console .print ()
310- console .print (
311- Panel (examples_text , title = "💡 Usage Examples" , border_style = "blue" )
312- )
332+ console .print ()
333+ console .print (
334+ Panel (examples_text , title = "💡 Python Usage Examples" , border_style = "blue" )
335+ )
313336
314- return 0
315337
316- except Exception as e :
317- console .print (f"[red]❌ Error getting language info:[/red] { e } " )
318- return 1
338+ def _show_go_examples ():
339+ """Show Go-specific CLI examples."""
340+ examples_text = """Generate basic structure:
341+ [cyan]json_explorer data.json --generate go[/cyan]
342+
343+ Generate to file:
344+ [cyan]json_explorer data.json --generate go --output output.go[/cyan]
345+
346+ Custom package name:
347+ [cyan]json_explorer data.json --generate go --package-name mypackage[/cyan]"""
348+
349+ console .print ()
350+ console .print (
351+ Panel (examples_text , title = "💡 Go Usage Examples" , border_style = "blue" )
352+ )
319353
320354
321355def _validate_language (language : str , silent : bool = False ) -> bool :
@@ -390,6 +424,25 @@ def _build_config(args: argparse.Namespace, language: str) -> GeneratorConfig:
390424 if hasattr (args , "json_tag_case" ) and args .json_tag_case :
391425 config_dict ["json_tag_case" ] = args .json_tag_case
392426
427+ elif language .lower () in ["python" , "py" ]:
428+ if hasattr (args , "python_style" ) and args .python_style :
429+ config_dict ["style" ] = args .python_style
430+
431+ if hasattr (args , "no_slots" ) and args .no_slots :
432+ config_dict ["dataclass_slots" ] = False
433+
434+ if hasattr (args , "frozen" ) and args .frozen :
435+ config_dict ["dataclass_frozen" ] = True
436+
437+ if hasattr (args , "kw_only" ) and args .kw_only :
438+ config_dict ["dataclass_kw_only" ] = True
439+
440+ if hasattr (args , "no_pydantic_field" ) and args .no_pydantic_field :
441+ config_dict ["pydantic_use_field" ] = False
442+
443+ if hasattr (args , "pydantic_forbid_extra" ) and args .pydantic_forbid_extra :
444+ config_dict ["pydantic_extra_forbid" ] = True
445+
393446 return load_config (custom_config = config_dict )
394447
395448
@@ -474,6 +527,8 @@ def _display_generated_code(code: str, language: str):
474527 syntax_lang = language .lower ()
475528 if syntax_lang == "golang" :
476529 syntax_lang = "go"
530+ elif syntax_lang == "py" :
531+ syntax_lang = "python"
477532
478533 syntax = Syntax (code , syntax_lang , theme = "monokai" , padding = 1 )
479534 console .print (syntax )
0 commit comments