@@ -207,49 +207,47 @@ def resolve_go_output_dir(base_go_out: Path, schema: Schema) -> Path:
207207def parse_args (args : Optional [List [str ]] = None ) -> argparse .Namespace :
208208 """Parse command line arguments."""
209209 parser = argparse .ArgumentParser (
210- prog = "fory " ,
210+ prog = "foryc " ,
211211 description = "Fory IDL compiler" ,
212212 )
213213
214- subparsers = parser .add_subparsers (dest = "command" , help = "Available commands" )
215-
216- # compile command
217- compile_parser = subparsers .add_parser (
218- "compile" ,
219- help = "Compile IDL files (.fdl, .proto, .fbs) to language-specific code" ,
214+ parser .add_argument (
215+ "--scan-generated" ,
216+ action = "store_true" ,
217+ help = "Scan for generated files under the current directory" ,
220218 )
221219
222- compile_parser .add_argument (
220+ parser .add_argument (
223221 "files" ,
224- nargs = "+ " ,
222+ nargs = "* " ,
225223 type = Path ,
226224 metavar = "FILE" ,
227225 help = "IDL files to compile" ,
228226 )
229227
230- compile_parser .add_argument (
228+ parser .add_argument (
231229 "--lang" ,
232230 type = str ,
233231 default = "all" ,
234232 help = "Comma-separated list of target languages (java,python,cpp,rust,go). Default: all" ,
235233 )
236234
237- compile_parser .add_argument (
235+ parser .add_argument (
238236 "--output" ,
239237 "-o" ,
240238 type = Path ,
241239 default = Path ("./generated" ),
242240 help = "Output directory. Default: ./generated" ,
243241 )
244242
245- compile_parser .add_argument (
243+ parser .add_argument (
246244 "--package" ,
247245 type = str ,
248246 default = None ,
249247 help = "Override package name from FDL file" ,
250248 )
251249
252- compile_parser .add_argument (
250+ parser .add_argument (
253251 "-I" ,
254252 "--proto_path" ,
255253 "--import_path" ,
@@ -262,83 +260,79 @@ def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
262260 )
263261
264262 # Language-specific output directories (protoc-style)
265- compile_parser .add_argument (
263+ parser .add_argument (
266264 "--java_out" ,
267265 type = Path ,
268266 default = None ,
269267 metavar = "DST_DIR" ,
270268 help = "Generate Java code in DST_DIR" ,
271269 )
272270
273- compile_parser .add_argument (
271+ parser .add_argument (
274272 "--python_out" ,
275273 type = Path ,
276274 default = None ,
277275 metavar = "DST_DIR" ,
278276 help = "Generate Python code in DST_DIR" ,
279277 )
280278
281- compile_parser .add_argument (
279+ parser .add_argument (
282280 "--cpp_out" ,
283281 type = Path ,
284282 default = None ,
285283 metavar = "DST_DIR" ,
286284 help = "Generate C++ code in DST_DIR" ,
287285 )
288286
289- compile_parser .add_argument (
287+ parser .add_argument (
290288 "--go_out" ,
291289 type = Path ,
292290 default = None ,
293291 metavar = "DST_DIR" ,
294292 help = "Generate Go code in DST_DIR" ,
295293 )
296294
297- compile_parser .add_argument (
295+ parser .add_argument (
298296 "--rust_out" ,
299297 type = Path ,
300298 default = None ,
301299 metavar = "DST_DIR" ,
302300 help = "Generate Rust code in DST_DIR" ,
303301 )
304302
305- compile_parser .add_argument (
303+ parser .add_argument (
306304 "--go_nested_type_style" ,
307305 type = str ,
308306 default = None ,
309307 choices = ["camelcase" , "underscore" ],
310308 help = "Go nested type naming style: camelcase or underscore (default)" ,
311309 )
312310
313- compile_parser .add_argument (
311+ parser .add_argument (
314312 "--emit-fdl" ,
315313 action = "store_true" ,
316314 help = "Emit translated FDL (for non-FDL inputs) for debugging" ,
317315 )
318316
319- compile_parser .add_argument (
317+ parser .add_argument (
320318 "--emit-fdl-path" ,
321319 type = Path ,
322320 default = None ,
323321 help = "Write translated FDL to this path (file or directory)" ,
324322 )
325323
326- scan_parser = subparsers .add_parser (
327- "scan-generated" ,
328- help = "Scan for generated files under the current directory" ,
329- )
330- scan_parser .add_argument (
324+ parser .add_argument (
331325 "--root" ,
332326 type = Path ,
333327 default = Path ("." ),
334328 help = "Root directory to scan (default: current directory)" ,
335329 )
336- scan_parser .add_argument (
330+ parser .add_argument (
337331 "--relative" ,
338332 action = "store_true" ,
339333 help = "Print paths relative to the scan root" ,
340334 )
341- delete_group = scan_parser .add_mutually_exclusive_group ()
335+ delete_group = parser .add_mutually_exclusive_group ()
342336 delete_group .add_argument (
343337 "--delete" ,
344338 action = "store_true" ,
@@ -353,6 +347,23 @@ def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
353347 return parser .parse_args (args )
354348
355349
350+ def normalize_args (args : Optional [List [str ]]) -> List [str ]:
351+ """Normalize args so compile is the default command."""
352+ if args is None :
353+ args = sys .argv [1 :]
354+ if not args :
355+ return []
356+ if args [0 ] in {"-h" , "--help" }:
357+ return args
358+ if args [0 ] == "--scan-generated" :
359+ return args
360+ if args [0 ] == "scan-generated" :
361+ return ["--scan-generated" , * args [1 :]]
362+ if args [0 ] == "compile" :
363+ return args [1 :]
364+ return args
365+
366+
356367def get_languages (lang_arg : str ) -> List [str ]:
357368 """Parse the language argument into a list of languages."""
358369 if lang_arg == "all" :
@@ -656,20 +667,17 @@ def cmd_scan_generated(args: argparse.Namespace) -> int:
656667
657668def main (args : Optional [List [str ]] = None ) -> int :
658669 """Main entry point."""
659- parsed = parse_args (args )
660-
661- if parsed .command is None :
662- print ("Usage: fory <command> [options]" , file = sys .stderr )
663- print ("Commands: compile, scan-generated" , file = sys .stderr )
664- print ("Use 'fory <command> --help' for more information" , file = sys .stderr )
665- return 1
670+ parsed = parse_args (normalize_args (args ))
666671
667- if parsed .command == "compile" :
668- return cmd_compile (parsed )
669- if parsed .command == "scan-generated" :
672+ if parsed .scan_generated :
670673 return cmd_scan_generated (parsed )
671674
672- return 0
675+ if not parsed .files :
676+ print ("Usage: foryc [--scan-generated] [options] FILES..." , file = sys .stderr )
677+ print ("Use 'foryc --help' for more information" , file = sys .stderr )
678+ return 1
679+
680+ return cmd_compile (parsed )
673681
674682
675683if __name__ == "__main__" :
0 commit comments