@@ -59,6 +59,44 @@ def __init__(self, config: Code2DocsConfig, result: AnalysisResult):
5959 self .result = result
6060 self ._pkg = self ._detect_package_name ()
6161
62+ def _get_example_value (self , arg_name : str ) -> str :
63+ """Get realistic example value based on actual project config."""
64+ project_name = self .config .project_name or Path (self .result .project_path ).name
65+
66+ # Map argument names to actual config values
67+ arg_mappings = {
68+ "project_path" : f'"./{ project_name } "' ,
69+ "path" : f'"./{ project_name } "' ,
70+ "source" : f'"{ self .config .source } "' if self .config .source else '"./src"' ,
71+ "output" : f'"{ self .config .output } "' if self .config .output else '"./docs"' ,
72+ "output_dir" : f'"{ self .config .output } "' if self .config .output else '"./docs"' ,
73+ "output_path" : f'"{ self .config .readme_output } "' if self .config .readme_output else '"./docs/README.md"' ,
74+ "config" : "config" ,
75+ "config_path" : '"code2docs.yaml"' ,
76+ "result" : "result" ,
77+ "name" : f'"{ project_name } "' ,
78+ "project_name" : f'"{ project_name } "' ,
79+ "verbose" : "True" ,
80+ "dry_run" : "False" ,
81+ "readme_only" : "False" ,
82+ "sections" : '["overview", "install", "quickstart"]' ,
83+ "content" : '"# My Doc\\ n## Section"' ,
84+ "markdown_content" : '"# My Doc\\ n## Section"' ,
85+ "max_depth" : "3" ,
86+ "target" : "80" ,
87+ "badge_types" : '["version", "python"]' ,
88+ "stats" : "{}" ,
89+ "deps" : "[]" ,
90+ "sync_markers" : "True" ,
91+ "docstring" : '"""My function docstring."""' ,
92+ }
93+
94+ if arg_name in arg_mappings :
95+ return arg_mappings [arg_name ]
96+
97+ # Fallback to original static examples
98+ return _ARG_EXAMPLES .get (arg_name , '"..."' )
99+
62100 def generate_all (self ) -> Dict [str , str ]:
63101 """Generate all example files. Returns {filename: content}."""
64102 files : Dict [str , str ] = {}
@@ -100,15 +138,18 @@ def _generate_quickstart(self) -> str:
100138
101139 # --- Example 1: Config (define first so later examples can use it) ---
102140 config_cls = self ._find_class_by_name ("Code2DocsConfig" )
141+ project_name = self .config .project_name or Path (self .result .project_path ).name
142+ source = self .config .source or "./"
143+ output = self .config .output or "./docs"
103144 if config_cls :
104145 lines .append ('# ' + '=' * 50 )
105146 lines .append ("# Example 1: Configuration" )
106147 lines .append ('# ' + '=' * 50 )
107148 lines .append ("" )
108149 lines .append (f"config = { config_cls .name } (" )
109- lines .append (' project_name="my-project ",' )
110- lines .append (' source="./src ",' )
111- lines .append (' output="./docs ",' )
150+ lines .append (f ' project_name="{ project_name } ",' )
151+ lines .append (f ' source="{ source } ",' )
152+ lines .append (f ' output="{ output } ",' )
112153 lines .append (" verbose=True," )
113154 lines .append (")" )
114155 lines .append ("" )
@@ -119,20 +160,22 @@ def _generate_quickstart(self) -> str:
119160 lines .append ("# Example 2: Generate documentation" )
120161 lines .append ('# ' + '=' * 50 )
121162 lines .append ("" )
163+
164+ project_path = f'"./{ project_name } "' if project_name != "." else '"./"'
122165
123166 gen_func = self ._find_function_by_name ("generate_readme" )
124167 if gen_func :
125168 lines .append ("# Generate a README for your project" )
126- lines .append ('generate_readme("./my-project" , output="README.md")' )
169+ lines .append (f 'generate_readme({ project_path } , output="README.md")' )
127170 lines .append ("" )
128171
129172 docs_func = self ._find_function_by_name ("generate_docs" )
130173 if docs_func :
131174 lines .append ("# Generate all documentation" )
132175 if config_cls :
133- lines .append ('docs = generate_docs("./my-project" , config=config)' )
176+ lines .append (f 'docs = generate_docs({ project_path } , config=config)' )
134177 else :
135- lines .append ('docs = generate_docs("./my-project" )' )
178+ lines .append (f 'docs = generate_docs({ project_path } )' )
136179 lines .append ('print(f"Generated {len(docs)} documentation sections")' )
137180 lines .append ("" )
138181
@@ -147,7 +190,7 @@ def _generate_quickstart(self) -> str:
147190 lines .append (f"from { pkg } .analyzers.project_scanner import ProjectScanner" )
148191 lines .append ("" )
149192 lines .append ("scanner = ProjectScanner(config)" )
150- lines .append ('result = scanner.analyze("./my-project" )' )
193+ lines .append (f 'result = scanner.analyze({ project_path } )' )
151194 lines .append ("" )
152195 lines .append ('print(f"Found {len(result.functions)} functions")' )
153196 lines .append ('print(f"Found {len(result.classes)} classes")' )
@@ -191,7 +234,7 @@ def _generate_advanced(self) -> str:
191234 lines .append ("# Step 1: Analyze the project" )
192235 lines .append ("config = Code2DocsConfig(project_name=\" my-project\" )" )
193236 lines .append ("scanner = ProjectScanner(config)" )
194- lines .append ('result = scanner.analyze("./my-project ")' )
237+ lines .append ('result = scanner.analyze(f "./${project_name_adv}") if project_name_adv != "." else result = scanner.analyze("./ ")' )
195238 lines .append ("" )
196239
197240 for i , cls in enumerate (gen_classes [:4 ], start = 2 ):
@@ -351,26 +394,27 @@ def _build_realistic_args(self, func: FunctionInfo) -> str:
351394 args = [a for a in func .args if a not in ("self" , "cls" )]
352395 parts = []
353396 for arg in args [:5 ]:
354- val = _ARG_EXAMPLES . get (arg )
355- if not val :
397+ val = self . _get_example_value (arg )
398+ if not val or val == '"..."' :
356399 # Try type hint
357400 val = self ._example_from_type (func , arg )
358401 if not val :
359402 val = '"..."'
360403 parts .append (f"{ arg } ={ val } " if len (args ) > 1 else val )
361404 return ", " .join (parts )
362405
363- @staticmethod
364- def _example_from_type (func : FunctionInfo , arg : str ) -> Optional [str ]:
406+ def _example_from_type (self , func : FunctionInfo , arg : str ) -> Optional [str ]:
365407 """Try to infer example value from type annotation."""
408+ project_name = self .config .project_name or Path (self .result .project_path ).name
409+
366410 # FunctionInfo.returns gives return type, but arg types
367411 # are not always available; use naming heuristics
368412 if "path" in arg .lower ():
369- return '"./my-project "'
413+ return f '"./{ project_name } "'
370414 if "name" in arg .lower ():
371- return '"my-project "'
415+ return f'" { project_name } "'
372416 if "dir" in arg .lower ():
373- return '"./docs"'
417+ return f'" { self . config . output } "' if self . config . output else '"./docs"'
374418 if arg .startswith ("is_" ) or arg .startswith ("enable" ):
375419 return "True"
376420 if "count" in arg .lower () or "max" in arg .lower () or "min" in arg .lower ():
0 commit comments