From 59515b7aa38b88b3a69a0ed32601978ece80e1cd Mon Sep 17 00:00:00 2001
From: Matthew K Defenderfer <mdefende@uab.edu>
Date: Thu, 15 Aug 2024 12:41:55 -0500
Subject: [PATCH] better arg handling

---
 convert-to-parquet/convert-to-parquet.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/convert-to-parquet/convert-to-parquet.py b/convert-to-parquet/convert-to-parquet.py
index 2f716b4..6fea930 100755
--- a/convert-to-parquet/convert-to-parquet.py
+++ b/convert-to-parquet/convert-to-parquet.py
@@ -21,9 +21,9 @@ def parse_args():
     parser = argparse.ArgumentParser(description=desc,
                                      formatter_class=argparse.RawTextHelpFormatter
                                      )
-    parser.add_argument('-p','--policy',help="Print the policy the script uses as a template and exit")
+    parser.add_argument('-p','--policy',help="Print the policy the script uses as a template and exit",action='store_true')
     parser.add_argument('-o','--output-dir',help="Directory to store the output parquet. The parquet file will have the same name as the input. Defaults to input_file_dir/parquet")
-    parser.add_argument('-f','--file',required=True,help="Log file from mmlspolicy run to be converted to parquet. Can be either a full log or just a part")
+    parser.add_argument('-f','--file',help="Log file from mmlspolicy run to be converted to parquet. Can be either a full log or just a part")
     args = parser.parse_args()
     return args
 
@@ -96,11 +96,15 @@ def main():
         print_policy()
         exit()
     
-    file   = PurePath(args.file)
-    outdir = PurePath(args.output_dir)
+    if args.file:
+        file = PurePath(args.file)
+    else:
+        exit('Error: must specify a file to convert')
 
-    if not outdir:
+    if not args.output_dir:
         outdir = file.parent.joinpath('parquet')
+    else:
+        outdir = PurePath(args.output_dir)
         
     os.makedirs(outdir,exist_ok=True)
     
-- 
GitLab