Description: Add or fix displayed support and help messages
 Add or improve the help messages displayed by the four main scripts.
Fowarded: https://github.com/kliment/Printrun/pull/727
Author: Rock Storm <rockstorm@gmx.com>

--- a/plater.py
+++ b/plater.py
@@ -17,10 +17,35 @@
 
 import sys
 import wx
+import getopt
 
 from printrun.stlplater import StlPlater
 
 if __name__ == '__main__':
+
+    from printrun.printcore import __version__ as printcore_version
+
+    usage = "Usage:\n"+\
+            "  plater [OPTION]\n"+\
+            "  plater FILES\n\n"+\
+            "Options:\n"+\
+            "  -V, --version\t\t\tPrint program's version number and exit\n"+\
+            "  -h, --help\t\t\tPrint this help message and exit\n"
+
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hV", ["help", "version"])
+    except getopt.GetoptError, err:
+        print str(err)
+        print usage
+        sys.exit(2)
+    for o, a in opts:
+        if o in ('-V','--version'):
+            print "printrun "+printcore_version
+            sys.exit(0)
+        elif o in ('-h', '--help'):
+            print usage
+            sys.exit(0)
+
     app = wx.App(False)
     main = StlPlater(filenames = sys.argv[1:])
     main.Show()
--- a/printcore.py
+++ b/printcore.py
@@ -28,32 +28,59 @@
     baud = 115200
     loud = False
     statusreport = False
+
+    from printrun.printcore import __version__ as printcore_version
+
+    usage = "Usage:\n"+\
+            "  printcore [OPTIONS] PORT FILE\n\n"+\
+            "Options:\n"+\
+            "  -b, --baud=BAUD_RATE"+\
+                        "\t\tSet baud rate value. Default value is 115200\n"+\
+            "  -s, --statusreport\t\tPrint progress as percentage\n"+\
+            "  -v, --verbose\t\t\tPrint additional progress information\n"+\
+            "  -V, --version\t\t\tPrint program's version number and exit\n"+\
+            "  -h, --help\t\t\tPrint this help message and exit\n"
+
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "h,b:,v,s",
-                                   ["help", "baud", "verbose", "statusreport"])
+        opts, args = getopt.getopt(sys.argv[1:], "b:svVh",
+                        ["baud=", "statusreport", "verbose", "version", "help"])
     except getopt.GetoptError, err:
         print str(err)
+        print usage
         sys.exit(2)
     for o, a in opts:
         if o in ('-h', '--help'):
-            # FIXME: Fix help
-            print ("Opts are: --help, -b --baud = baudrate, -v --verbose, "
-                   "-s --statusreport")
-            sys.exit(1)
-        if o in ('-b', '--baud'):
-            baud = int(a)
-        if o in ('-v', '--verbose'):
+            print usage
+            sys.exit(0)
+        elif o in ('-V','--version'):
+            print "printrun "+printcore_version
+            sys.exit(0)
+        elif o in ('-b','--baud'):
+            try:
+                baud = int(a)
+            except ValueError:
+                print "ValueError:"
+                print "\tInvalid BAUD_RATE value '%s'" % a
+                print "\tBAUD_RATE must be an integer\n"
+                # FIXME: This should output a more apropiate error message when
+                #        not a good baud rate is passed as an argument
+                #        i.e: when baud <= 1000 or > 225000
+                print usage
+                sys.exit(2)
+        elif o in ('-v', '--verbose'):
             loud = True
         elif o in ('-s', '--statusreport'):
             statusreport = True
 
-    if len(args) > 1:
+    if len(args) <= 1:
+        print "Error: Port or gcode file were not specified.\n"
+        print usage
+        sys.exit(2)
+    elif len(args) > 1:
         port = args[-2]
         filename = args[-1]
         print "Printing: %s on %s with baudrate %d" % (filename, port, baud)
-    else:
-        print "Usage: python [-h|-b|-v|-s] printcore.py /dev/tty[USB|ACM]x filename.gcode"
-        sys.exit(2)
+
     p = printcore(port, baud)
     p.loud = loud
     time.sleep(2)
--- a/pronsole.py
+++ b/pronsole.py
@@ -19,9 +19,32 @@
 import traceback
 import logging
 from printrun.pronsole import pronsole
+import getopt
 
 if __name__ == "__main__":
 
+    from printrun.printcore import __version__ as printcore_version
+
+    usage = "Usage:\n"+\
+            "  pronsole [OPTION]\n\n"+\
+            "Options:\n"+\
+            "  -V, --version\t\t\tPrint program's version number and exit\n"+\
+            "  -h, --help\t\t\tPrint this help message and exit\n"
+
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hV", ["help", "version"])
+    except getopt.GetoptError, err:
+        print str(err)
+        print usage
+        sys.exit(2)
+    for o, a in opts:
+        if o in ('-V','--version'):
+            print "printrun "+printcore_version
+            sys.exit(0)
+        elif o in ('-h', '--help'):
+            print usage
+            sys.exit(0)
+
     interp = pronsole()
     interp.parse_cmdline(sys.argv[1:])
     try:
--- a/pronterface.py
+++ b/pronterface.py
@@ -16,6 +16,7 @@
 # along with Printrun.  If not, see <http://www.gnu.org/licenses/>.
 
 import sys
+import getopt
 
 try:
     import wx  # NOQA
@@ -32,6 +33,29 @@
 from printrun.pronterface import PronterApp
 
 if __name__ == '__main__':
+
+    from printrun.printcore import __version__ as printcore_version
+
+    usage = "Usage:\n"+\
+            "  pronterface [OPTION]\n\n"+\
+            "Options:\n"+\
+            "  -V, --version\t\t\tPrint program's version number and exit\n"+\
+            "  -h, --help\t\t\tPrint this help message and exit\n"
+
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hV", ["help", "version"])
+    except getopt.GetoptError, err:
+        print str(err)
+        print usage
+        sys.exit(2)
+    for o, a in opts:
+        if o in ('-V','--version'):
+            print "printrun "+printcore_version
+            sys.exit(0)
+        elif o in ('-h', '--help'):
+            print usage
+            sys.exit(0)
+
     app = PronterApp(False)
     try:
         app.MainLoop()
