(args, extra_args)
| 89 | |
| 90 | |
| 91 | def cmd_run(args, extra_args): |
| 92 | try: |
| 93 | model = ifcopenshell.open(args.ifc_file) |
| 94 | except Exception as e: |
| 95 | print(f"Error: Could not open IFC file: {e}", file=sys.stderr) |
| 96 | sys.exit(1) |
| 97 | |
| 98 | parts = args.function_path.split(".") |
| 99 | if len(parts) != 2: |
| 100 | print("Error: function path must be 'module.function' (e.g. root.create_entity)", file=sys.stderr) |
| 101 | sys.exit(1) |
| 102 | module, function = parts |
| 103 | |
| 104 | # Parse extra --key value arguments into a dict |
| 105 | raw_kwargs = _parse_extra_args(extra_args) |
| 106 | |
| 107 | if args.dry_run: |
| 108 | result = {"ok": True, "dry_run": True, "module": module, "function": function, "args": raw_kwargs} |
| 109 | else: |
| 110 | result = run_api(model, module, function, raw_kwargs) |
| 111 | |
| 112 | if result["ok"]: |
| 113 | output_path = args.output or args.ifc_file |
| 114 | model.write(output_path) |
| 115 | |
| 116 | print(format_output(result, args.output_format)) |
| 117 | if not result["ok"]: |
| 118 | sys.exit(1) |
| 119 | |
| 120 | |
| 121 | def _parse_extra_args(extra: list[str]) -> dict[str, str]: |
no test coverage detected