commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/gnue-common/src GBaseApp.py


From: Jason Cater
Subject: gnue/gnue-common/src GBaseApp.py
Date: Thu, 18 Oct 2001 15:54:05 -0400

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    01/10/18 15:54:05

Modified files:
        gnue-common/src: GBaseApp.py 

Log message:
        Added support for long-parameter only command line options (e.g., 
--profile has no short option; used to be --profile or -p, but that seems a 
waste of a single letter code)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/GBaseApp.py.diff?cvsroot=OldCVS&tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: gnue/gnue-common/src/GBaseApp.py
diff -u gnue/gnue-common/src/GBaseApp.py:1.3 
gnue/gnue-common/src/GBaseApp.py:1.4
--- gnue/gnue-common/src/GBaseApp.py:1.3        Thu Sep 27 22:05:04 2001
+++ gnue/gnue-common/src/GBaseApp.py    Thu Oct 18 15:54:05 2001
@@ -70,16 +70,16 @@
     #       [dictionary key name, short option, long option,
     #        argument follows option?, argument name, help message]
     self._base_options = [
-         [ 'version','v','version',0,0, None,
+         [ 'version',None,'version',0,0, None,
            'Displays the version information for this program.' ],
-         [ 'debug_level','d','debug_level',1,0, "level",
+         [ 'debug_level','d','debug-level',1,0, "level",
            'Enables debugging messages.  Argument specifies the ' + \
            'level of messages to display (e.g., "-d5" displays ' + \
            'all debugging messages at level 5 or below.)' ],
-         [ 'debug_file','D','debug_file',1,None, "file",
+         [ 'debug_file',None,'debug-file',1,None, "file",
            'Sends all debugging messages to a specified file ' + \
-           '(e.g., "-D trace.log" sends all output to "trace.log")' ],
-         [ 'connections', 'f', 'connections', 1, None, "loc",
+           '(e.g., "--debug-file trace.log" sends all output to "trace.log")' 
],
+         [ 'connections', None, 'connections', 1, None, "loc",
            'Specifies the location of the connection definition file. ' + \
            '<loc> may specify a file name ' + \
            '(/usr/local/gnue/etc/connections.conf), ' + \
@@ -87,9 +87,9 @@
            '(http://localhost/connections.conf). '+ \
            'If this option is not specified, the environent variable ' + \
            'GNUE_CONNECTIONS is checked.' ],
-         [ 'help', 'h', 'help', 0, None, None,
+         [ 'help', None, 'help', 0, None, None,
            'Displays this help screen.' ],
-         [ 'profile', 'p', 'profile', 0, None, None,
+         [ 'profile', None, 'profile', 0, None, None,
            "Run Python's built-in profiler and display the resulting " + \
            "run statistics." ],
     ]
@@ -103,8 +103,9 @@
     for optionset in [self._base_options, self.COMMAND_OPTIONS]: 
       for option in optionset:  
         self.OPTIONS[option[0]] = option[4] 
-        shortoptions = shortoptions + option[1]
-        lookup["-" + option[1]] = option[0]
+        if option[1] != None: 
+          shortoptions = shortoptions + option[1]
+          lookup["-" + option[1]] = option[0]
         lookup["--" + option[2]] = option[0]
         lo = option[2]
         if option[3]:   
@@ -199,7 +200,10 @@
     maxArg = 0
     for optionset in [self._base_options, self.COMMAND_OPTIONS]: 
       for option in optionset:  
-        allOptions[string.upper(option[1]) + option[1]] = option
+#        if option[1] != None: 
+#          allOptions[string.upper(option[1]) + option[1]] = option
+#        else: 
+        allOptions[string.upper(option[2])] = option
         if len(option[2]) > maxLength: 
           maxLength = len(option[2])
         if option[3] and len(option[5]) > maxArg: 
@@ -210,16 +214,25 @@
 
     dispOptions = ""
 
+    print maxLength
+
     for optionKey in sorted: 
       if allOptions[optionKey][3]:
-        valMarker = ("<%s>" % allOptions[optionKey][5]) + \
-                    " " * (maxArg - len(allOptions[optionKey][5]))
+        valMarker = (" <%s>" % allOptions[optionKey][5])
+        extraspace = " " * (maxArg-len(allOptions[optionKey][5]))
+      else: 
+        valMarker = ""
+        extraspace = " "*(maxArg+3)
+
+      if allOptions[optionKey][1] != None: 
+        short = ", -%s" % (allOptions[optionKey][1])
       else: 
-        valMarker = " " * (maxArg+2)
+        short = "    " 
+
       dispOptions = dispOptions + "\n" +\
-           ("  -%s, --%s %s " % (allOptions[optionKey][1], 
-                                  allOptions[optionKey][2], valMarker)) +\
-           " "*(maxLength-len(allOptions[optionKey][2]))
+           ("   --%s%s%s" % (allOptions[optionKey][2], valMarker, short)) +\
+           extraspace + \
+           (" "*(maxLength-len(allOptions[optionKey][2])))
 
       margin = maxLength + 12 + maxArg
       width = 78 - margin
@@ -250,10 +263,10 @@
       self.printVersion()
 
       # if msg is multiline, then surround with dashes to set it apart
-      if string.find(msg, "\n") + 1:
+      if string.find("%s" % msg, "\n") + 1:
         print '-' * 60
       print "Error: %s" % msg
-      if string.find(msg, "\n") + 1:
+      if string.find("%s" % msg, "\n") + 1:
         print '-' * 60
       print "\nFor help, type:\n   %s --help\n" % (self.COMMAND)
       sys.exit()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]