umlet / pwk

Python With Kurly braces
94 stars 4 forks source link

ArgParse and better error printing #6

Closed JoaquimEsteves closed 3 years ago

JoaquimEsteves commented 3 years ago

Argparse is the natural way to organise command line arguments in python.

Adding it will make it easier to add further options to the program (See for example #5).

I've also made error messages clearer by taking out the useless Traceback.

$ ./pwk 'print(yo)'
NameError: name 'yo' is not defined

The relevant lines are:

try:
    exec(compile(cmd_string, "<pwk>", "exec"))
except Exception as e:
    # The compile step helps us be more specific when it comes to errors
    import traceback

    # Prints the SyntaxErrors in a friendlier format
    traceback.print_exception(None, e, None)
    sys.exit(1)
umlet commented 3 years ago

REALLY SORRY for my late response! Personally, I do not like argparse (in my very personal view, its naming/structure is opaque and prevents me from using info about args I like to have and act upon), and I prefer C-style getopt logic (not applied here yet; I have a separate code snippet that'll get pasted in once I need more extensive arg handling, e.g., for config files etc.).

JoaquimEsteves commented 3 years ago

No issues. Thanks for all of your work :)