Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why you don't use argparse for parsing arguments? #1

Open
folkien opened this issue Jan 24, 2020 · 1 comment
Open

Why you don't use argparse for parsing arguments? #1

folkien opened this issue Jan 24, 2020 · 1 comment
Assignees

Comments

@folkien
Copy link

folkien commented Jan 24, 2020

Why you don't use argparse for parsing arguments? It's far more easier to use, code and works as standards. Example below

parser = argparse.ArgumentParser()
parser.add_argument("-a", "--addAlarm",    action='store_true', required=False, help="Adds given alarm")
parser.add_argument("-d", "--deleteAlarm", action='store_true', required=False, help="Removes alarm")
parser.add_argument("-c", "--checkAlarms", action='store_true', required=False, help="Check all alarms")
parser.add_argument("-p", "--printAlarms", action='store_true', required=False, help="Print all alarms")
parser.add_argument("-n", "--stockCode", type=str, required=False, help="")
parser.add_argument("-r", "--referencePrice", type=float, required=False, help="")
parser.add_argument("-t", "--type", type=str, required=False, help="")
parser.add_argument("-v", "--value", type=float, required=False, help="")
parser.add_argument("-W", "--lastWeek", action='store_true', required=False, help="Last Week")
args = parser.parse_args()

#Assert
if (not args.addAlarm and not args.checkAlarms and not args.deleteAlarm and not args.printAlarms):
    print "Missing event"
    sys.exit(1)

if (args.addAlarm):
    if (not args.stockCode or not args.referencePrice or not args.type or not args.value):
        print "Missing arguments for adding."
        sys.exit(1)

if (args.deleteAlarm):
    if (not args.stockCode or not args.referencePrice or not args.type or not args.value):
        print "Missing arguments for removal."
        sys.exit(1)`
@eantoranz
Copy link
Owner

Having worked with argparse in the last few months, I agree. Might sit down to code it.

@eantoranz eantoranz self-assigned this Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants