check for argument "-d" if len(argv) is 4
[pyfrprog.git] / frprog.py
index ab8aba66bc8b71c869829e6c379fa1ed9fdc2cee..f87dbc01c6f90ecb161faf6d132b76e628aed585 100755 (executable)
--- a/frprog.py
+++ b/frprog.py
@@ -177,18 +177,32 @@ def readMHXFile(filename): # desired mhx filename
        fp.close()
        return retval
 
+def usage(execfile):
+       print "Usage: " + execfile + " <target mhx-file> [-d DEVICE]"
+
 def main(argv=None):
        # check command line arguments
        if argv is None:
                argv = sys.argv
+
+       if len(argv) == 2 and (argv[1] == "-v" or argv[1] == "--version"):
+               print "Version: %VERSION%"
+               return 0
+
        if len(argv) != 2 and len(argv) != 4:
-               print "Usage: " + argv[0] + " <target mhx-file> [-d DEVICE]"
+               usage(argv[0])
                return 1
 
        # standard serial device to communicate with
        DEVICE="/dev/ttyUSB0"
+
+       # overrule standard device if provided with -d
        if len(argv) == 4:
-               DEVICE = argv[3]
+               if argv[2] == "-d":
+                       DEVICE = argv[3]
+               else:
+                       usage(argv[0])
+                       return 1
 
        # read in data from mhx-files before starting
        try: