Skip to content

Commit ee8a02c

Browse files
committed
Generalize export format flag input
1 parent f442fd9 commit ee8a02c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tools/memap.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,15 @@ def parse_toolchain(string) :
486486
else:
487487
return newstring
488488

489+
export_formats = ["json", "csv-ci", "table"]
490+
@staticmethod
491+
def parse_export_format(string):
492+
newstring = string.lower().replace("_","-")
493+
if newstring not in MemapParser.export_formats:
494+
raise (argparse.ArgumentTypeError("{} is not a supported export format. Supported export formats are {}".format(string, ", ".join(MemapParser.export_formats))))
495+
else :
496+
return newstring
497+
489498
def main():
490499

491500
version = '0.3.10'
@@ -500,8 +509,8 @@ def main():
500509

501510
parser.add_argument('-o', '--output', help='output file name', required=False)
502511

503-
parser.add_argument('-e', '--export', dest='export', required=False,\
504-
help="export format (examples: 'json', 'csv-ci', 'table': default)")
512+
parser.add_argument('-e', '--export', dest='export', required=False, default='table', type=MemapParser.parse_export_format,\
513+
help="export format (examples: %s: default)" % ", ".join(MemapParser.export_formats))
505514

506515
parser.add_argument('-v', '--version', action='version', version=version)
507516

@@ -521,10 +530,6 @@ def main():
521530
if memap.parse(args.file, args.toolchain) is False:
522531
sys.exit(0)
523532

524-
# default export format is table
525-
if not args.export:
526-
args.export = 'table'
527-
528533
# Write output in file
529534
if args.output != None:
530535
memap.generate_output(args.export, args.output)

0 commit comments

Comments
 (0)