diff --git a/parse.py b/parse.py index 24abd8c..1cdeaac 100644 --- a/parse.py +++ b/parse.py @@ -60,13 +60,22 @@ def parse(input, format, **kwargs): return schematic +def main(args): + schematic = parse(**vars(args)) + + if args.output: + json_file = open(args.output, 'w') + json.dump(schematic, json_file, indent=4) + else: + print(schematic) + if __name__ == "__main__": parser = argparse.ArgumentParser(description='Converts Altium .SchDoc files into json.', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--input', '-i', dest='input', help='path/to/altiumschematic.schdoc file to parse') parser.add_argument('--output', '-o', dest='output', help='path/to/jsonfile.json file to output json to, otherwise prints to terminal') - parser.add_argument('format', default='hierarchy', nargs='?', + parser.add_argument('format', nargs='?', default='json-hierarchy', choices=['json-flat', 'json-hierarchy', 'parts-list', 'net-list'], help=textwrap.dedent('''\ json-flat, json-hierarchy: Organize records into owner/child "hierarchy" or leave as a "flat" list @@ -74,10 +83,4 @@ if __name__ == "__main__": net-list: A listing of nets between parts pins, referred to by their designators''')) args = parser.parse_args() - schematic = parse(**vars(args)) - - if args.output: - json_file = open(args.output, 'w') - json.dump(schematic, json_file, indent=4) - else: - print(schematic) \ No newline at end of file + main(args) \ No newline at end of file