changeset 231:553dfa009650

Added `--version` argument to `wk`.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 14 Mar 2014 21:35:30 -0700
parents f74fe4d3e626
children dbc855c585cf
files wikked/witch.py
diffstat 1 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/wikked/witch.py	Fri Mar 14 08:37:37 2014 -0700
+++ b/wikked/witch.py	Fri Mar 14 21:35:30 2014 -0700
@@ -1,4 +1,5 @@
 import sys
+import os.path
 import logging
 import argparse
 import datetime
@@ -45,6 +46,7 @@
     arg_debug = False
     arg_quiet = False
     arg_debug_sql = False
+    arg_version = False
     for i, arg in enumerate(sys.argv[1:]):
         if not arg.startswith('--'):
             break
@@ -57,6 +59,11 @@
             i += 1
         elif arg == '--debugsql':
             arg_debug_sql = True
+        elif arg == '--version':
+            arg_version = True
+
+    if arg_version:
+        return print_version()
     if arg_debug and arg_quiet:
         raise Exception("You can't specify both --debug and --quiet.")
     root_logger = logging.getLogger()
@@ -84,10 +91,13 @@
             help="Show debug information for SQLAlchemy (advanced)",
             action='store_true')
     parser.add_argument('--quiet',
-            help="Print only important information.",
+            help="Print only important information",
             action='store_true')
     parser.add_argument('--log',
-            help="Send log messages to the specified file.")
+            help="Send log messages to the specified file")
+    parser.add_argument('--version',
+            help="Print version and exit",
+            action='store_true')
 
     # Import the commands.
     # (this creates a PyLint warning but it's OK)
@@ -136,3 +146,14 @@
         delta = after - before
         logger.debug("Ran command in %fs" % delta.total_seconds())
 
+def print_version():
+    if os.path.isdir(os.path.join(os.path.dirname(__file__), '..', '.hg')):
+        print "Wikked (development version)"
+        return 0
+    try:
+        from wikked.__version__ import version
+    except ImportError:
+        print "Can't find version information."
+        return 1
+    print "Wikked %s" % version
+    return 0