Skip to content

Commit

Permalink
mplemented command line argument parsing using argparse for enhanced …
Browse files Browse the repository at this point in the history
…usability and error handling, allowing for the specification of JSON files with the -f option and providing a --help message for user guidance
  • Loading branch information
zoldax committed Oct 31, 2023
1 parent b0726a5 commit 5d6e8a1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions DASHreadme.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import json
import sys
import logging
import argparse

# Set up logging
logging.basicConfig(filename='ERROR.log', level=logging.ERROR)

if len(sys.argv) != 2:
error_message = "Usage: python DASHreadme.py file.json"
print(error_message)
logging.error(error_message)
sys.exit(1)
parser = argparse.ArgumentParser(description='DASHreadme by Pascal Weber (zoldax)')
parser.add_argument('-f', '--file', help='Name of the JSON file', required=True)
args = parser.parse_args()

filename = sys.argv[1]
filename = args.file
if not filename.endswith('.json'):
error_message = "The file must have a .json extension"
print(error_message)
Expand Down

0 comments on commit 5d6e8a1

Please sign in to comment.