|
1 | 1 | import sys |
2 | | -import time |
| 2 | +import json |
| 3 | +import argparse |
3 | 4 | from . import parse, ValidationError |
4 | 5 |
|
5 | | -if __name__ == "__main__": |
6 | | - args = [x for x in sys.argv[1:] if not x.startswith("-")] |
7 | | - flags = [x for x in sys.argv[1:] if x.startswith("-")] |
8 | | - |
9 | | - fn = args[0] |
10 | | - start_time = time.time() |
11 | | - |
| 6 | +def main(): |
| 7 | + parser = argparse.ArgumentParser(description="Parse and validate STEP file.") |
| 8 | + parser.add_argument("filename", help="The STEP file to validate.") |
| 9 | + parser.add_argument("--progress", action="store_true", help="Show progress during validation.") |
| 10 | + parser.add_argument("--json", action="store_true", help="Output errors in JSON format.") |
| 11 | + parser.add_argument("--only-header", action="store_true", help="Validate only the header section.") |
| 12 | + |
| 13 | + args = parser.parse_args() |
| 14 | + |
12 | 15 | try: |
13 | | - parse(filename=fn, with_progress="--progress" in flags, with_tree=False) |
14 | | - if "--json" not in flags: |
| 16 | + parse( |
| 17 | + filename=args.filename, |
| 18 | + with_progress = args.progress, |
| 19 | + with_tree = False, |
| 20 | + only_header=args.only_header, |
| 21 | + ) |
| 22 | + if not args.json: |
15 | 23 | print("Valid", file=sys.stderr) |
16 | 24 | exit(0) |
17 | 25 | except ValidationError as exc: |
18 | | - if "--json" not in flags: |
| 26 | + if not args.json: |
19 | 27 | print(exc, file=sys.stderr) |
20 | 28 | else: |
21 | | - import sys |
22 | | - import json |
23 | | - |
24 | 29 | json.dump(exc.asdict(), sys.stdout) |
25 | 30 | exit(1) |
| 31 | + |
| 32 | +if __name__ == '__main__': |
| 33 | + main() |
0 commit comments