[LNT] r211603 - [lnttool] Add --version command line option.
Daniel Dunbar
daniel at zuster.org
Tue Jun 24 09:11:00 PDT 2014
Author: ddunbar
Date: Tue Jun 24 11:10:59 2014
New Revision: 211603
URL: http://llvm.org/viewvc/llvm-project?rev=211603&view=rev
Log:
[lnttool] Add --version command line option.
Modified:
lnt/trunk/lnt/lnttool/main.py
lnt/trunk/lnt/util/multitool.py
Modified: lnt/trunk/lnt/lnttool/main.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/lnttool/main.py?rev=211603&r1=211602&r2=211603&view=diff
==============================================================================
--- lnt/trunk/lnt/lnttool/main.py (original)
+++ lnt/trunk/lnt/lnttool/main.py Tue Jun 24 11:10:59 2014
@@ -436,7 +436,7 @@ error: installed distribution %s is not
LNT or rerun 'setup.py develop' if using development mode.""" % (
installed_dist_name, current_dist_name))
-tool = lnt.util.multitool.MultiTool(locals())
+tool = lnt.util.multitool.MultiTool(locals(), "LNT %s" % (lnt.__version__,))
def main(*args, **kwargs):
_version_check()
Modified: lnt/trunk/lnt/util/multitool.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/multitool.py?rev=211603&r1=211602&r2=211603&view=diff
==============================================================================
--- lnt/trunk/lnt/util/multitool.py (original)
+++ lnt/trunk/lnt/util/multitool.py Tue Jun 24 11:10:59 2014
@@ -25,7 +25,9 @@ class MultiTool(object):
"-debug" are not listed in the help.
"""
- def __init__(self, locals):
+ def __init__(self, locals, version=None):
+ self.version = version
+
# Create the list of commands.
self.commands = dict((name[7:].replace('_','-'), f)
for name,f in locals.items()
@@ -51,10 +53,26 @@ Use ``%s <command> --help`` for more inf
if args is None:
args = sys.argv
- if len(args) < 2 or args[1] not in self.commands:
- if len(args) >= 2:
- print >>sys.stderr,"error: invalid command %r\n" % args[1]
- self.usage(args[0])
+ progname = os.path.basename(args.pop(0))
+
+ # Parse immediate command line options.
+ while args and args[0].startswith("-"):
+ option = args.pop(0)
+ if option in ("-h", "--help"):
+ self.usage(progname)
+ elif option in ("-v", "--version") and self.version is not None:
+ print self.version
+ return
+ else:
+ print >>sys.stderr, "error: invalid option %r\n" % (option,)
+ self.usage(progname)
+
+ if not args:
+ self.usage(progname)
+
+ cmd = args.pop(0)
+ if cmd not in self.commands:
+ print >>sys.stderr,"error: invalid command %r\n" % cmd
+ self.usage(progname)
- cmd = args[1]
- self.commands[cmd]('%s %s' % (os.path.basename(args[0]), cmd), args[2:])
+ self.commands[cmd]('%s %s' % (progname, cmd), args)
More information about the llvm-commits
mailing list