Skip to content

Commit 502cc33

Browse files
Ghesselinkaothms
authored andcommitted
use namespaces instead of kw args
1 parent a9715f0 commit 502cc33

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

__main__.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
import sys
2-
import time
2+
import json
3+
import argparse
34
from . import parse, ValidationError
45

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-
filename = args[0]
10-
start_time = time.time()
11-
12-
with_progress = "--progress" in flags
13-
json_output = "--json" in flags
14-
only_header = "--header-only" in flags
15-
validate_data_only = "--data-only" in flags
16-
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+
parser.add_argument("--only-data", action="store_true", help="Validate only the data section.")
1713

18-
# Sanity check: can't use both at once
19-
if only_header and validate_data_only:
20-
print("Cannot use both --header-only and --data-only at the same time", file=sys.stderr)
14+
args = parser.parse_args()
15+
if args.only_header and args.only_data:
16+
print("Cannot use both --only-header and --only-data at the same time", file=sys.stderr)
2117
sys.exit(2)
22-
18+
2319
try:
2420
parse(
25-
filename=filename,
26-
with_progress=with_progress,
27-
with_tree=False,
28-
only_header=only_header,
29-
validate_data_only=validate_data_only,
21+
filename=args.filename,
22+
with_progress = args.progress,
23+
with_tree = False,
24+
only_header=args.only_header,
25+
validate_data_only = args.only_data
3026
)
31-
if not json_output:
27+
if not args.json:
3228
print("Valid", file=sys.stderr)
3329
exit(0)
3430
except ValidationError as exc:
35-
if not json_output:
31+
if not args.json:
3632
print(exc, file=sys.stderr)
3733
else:
38-
import sys
39-
import json
40-
4134
json.dump(exc.asdict(), sys.stdout)
4235
exit(1)
36+
37+
if __name__ == '__main__':
38+
main()

0 commit comments

Comments
 (0)