[llvm-commits] [zorg] r130825 - /zorg/trunk/lnt/lnt/lnttool/__init__.py
Daniel Dunbar
daniel at zuster.org
Tue May 3 18:48:36 PDT 2011
Author: ddunbar
Date: Tue May 3 20:48:36 2011
New Revision: 130825
URL: http://llvm.org/viewvc/llvm-project?rev=130825&view=rev
Log:
lnt: Add a --version argument.
Modified:
zorg/trunk/lnt/lnt/lnttool/__init__.py
Modified: zorg/trunk/lnt/lnt/lnttool/__init__.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/lnt/lnt/lnttool/__init__.py?rev=130825&r1=130824&r2=130825&view=diff
==============================================================================
--- zorg/trunk/lnt/lnt/lnttool/__init__.py (original)
+++ zorg/trunk/lnt/lnt/lnttool/__init__.py Tue May 3 20:48:36 2011
@@ -5,6 +5,7 @@
from optparse import OptionParser, OptionGroup
import StringIO
+import lnt
from lnt import testing
from lnt.db import perfdb
@@ -401,28 +402,27 @@
commands = dict((name[7:], f) for name,f in locals().items()
if name.startswith('action_'))
-
-def usage():
- print >>sys.stderr, "Usage: %s command [options]" % (
- os.path.basename(sys.argv[0]))
- print >>sys.stderr
- print >>sys.stderr, "Available commands:"
+def main():
cmds_width = max(map(len, commands))
- for name,func in sorted(commands.items()):
- print >>sys.stderr, " %-*s - %s" % (cmds_width, name, func.__doc__)
- sys.exit(1)
+ parser = OptionParser("""\
+%%prog [options] <command> ... arguments ...
-def main():
- import sys
+Available commands:
+%s""" % ("\n".join(" %-*s - %s" % (cmds_width, name, func.__doc__)
+ for name, func in sorted(commands.items()))),
+ version = "lnt version %s" % lnt.__version__)
+ parser.disable_interspersed_args()
+ (opts, args) = parser.parse_args()
- if len(sys.argv) < 2 or sys.argv[1] not in commands:
- if len(sys.argv) >= 2:
- print >>sys.stderr,"error: invalid command %r\n" % sys.argv[1]
+ if not args:
+ parser.print_usage()
+ return
- usage()
+ cmd = args[0]
+ if cmd not in commands:
+ parser.error("invalid command: %r" % cmd)
- cmd = sys.argv[1]
- commands[cmd](cmd, sys.argv[2:])
+ commands[cmd](cmd, args[1:])
if __name__ == '__main__':
main()
More information about the llvm-commits
mailing list