Handle the compile command.
(args: argparse.Namespace)
| 952 | |
| 953 | |
| 954 | def cmd_compile(args: argparse.Namespace) -> int: |
| 955 | """Handle the compile command.""" |
| 956 | # Build language -> output directory mapping |
| 957 | # Language-specific --{lang}_out options take precedence |
| 958 | lang_specific_outputs = { |
| 959 | "java": args.java_out, |
| 960 | "python": args.python_out, |
| 961 | "cpp": args.cpp_out, |
| 962 | "go": args.go_out, |
| 963 | "rust": args.rust_out, |
| 964 | "csharp": args.csharp_out, |
| 965 | "javascript": args.javascript_out, |
| 966 | "swift": args.swift_out, |
| 967 | "dart": args.dart_out, |
| 968 | "scala": args.scala_out, |
| 969 | "kotlin": args.kotlin_out, |
| 970 | } |
| 971 | |
| 972 | # Determine which languages to generate |
| 973 | lang_output_dirs: Dict[str, Path] = {} |
| 974 | |
| 975 | # First, add languages specified via --{lang}_out (these use direct paths) |
| 976 | for lang, out_dir in lang_specific_outputs.items(): |
| 977 | if out_dir is not None: |
| 978 | lang_output_dirs[lang] = out_dir |
| 979 | |
| 980 | # Then, add languages from --lang that don't have specific output dirs |
| 981 | # These use output_dir/lang pattern |
| 982 | if args.lang != "all" or not lang_output_dirs: |
| 983 | # Only use --lang if no language-specific outputs are set, or if --lang is explicit |
| 984 | languages_from_arg = get_languages(args.lang) |
| 985 | for lang in languages_from_arg: |
| 986 | if lang not in lang_output_dirs: |
| 987 | lang_output_dirs[lang] = args.output / lang |
| 988 | |
| 989 | if not lang_output_dirs: |
| 990 | print("Error: No target languages specified.", file=sys.stderr) |
| 991 | print("Use --lang or --{lang}_out options.", file=sys.stderr) |
| 992 | return 1 |
| 993 | |
| 994 | # Validate that all languages are supported |
| 995 | invalid = [lang for lang in lang_output_dirs.keys() if lang not in GENERATORS] |
| 996 | if invalid: |
| 997 | print(f"Error: Unknown language(s): {', '.join(invalid)}", file=sys.stderr) |
| 998 | print(f"Available: {', '.join(GENERATORS.keys())}", file=sys.stderr) |
| 999 | return 1 |
| 1000 | |
| 1001 | # Resolve and validate import paths (support comma-separated paths) |
| 1002 | import_paths = [] |
| 1003 | for p in args.import_paths: |
| 1004 | # Split by comma to support multiple paths in one option |
| 1005 | for part in str(p).split(","): |
| 1006 | part = part.strip() |
| 1007 | if not part: |
| 1008 | continue |
| 1009 | resolved = Path(part).resolve() |
| 1010 | if not resolved.is_dir(): |
| 1011 | print( |