Commits

Jan Borsodi committed 6e7fed5

Version option is now handled with a custom action, this means that the version of argparse does not matter anymore.

Comments (0)

Files changed (1)

 import os
 from copy import copy
 import shutil
-from distutils.version import LooseVersion as Version
 
 from hob.proto import OperaValidator, ValidationError, PackageManager, ErrorType, iterTree, Config, ConfigError, Target, defaultPath
 from hob.template import TextGenerator
     "pdb": False,
 }
 
-# If we have argparse >= 1.1 then we also allow -v for verbose option
-_short_verbose = ''
-if Version(argparse.__version__) >= '1.1':
-    _short_verbose = 'v'
+def showVersion(version):
+    "Returns an argparse Action for showing the program version"
+    class ShowVersion(argparse.Action):
+        def __init__(self, **kwargs):
+            kwargs.update(
+                dict(
+                    dest=argparse.SUPPRESS,
+                    default=argparse.SUPPRESS,
+                    nargs=0,
+                )
+            )
+            super(ShowVersion, self).__init__(**kwargs)
+
+        def __call__(self, parser, namespace, values, option_string=None):
+            parser.exit(message=version)
+
+    return ShowVersion
 
 global_options = [
-    (_short_verbose, 'verbose', False,
+    ('v', 'verbose', False,
      _('increase verbosity')),
+    ('', 'version', False,
+     _("show program's version number and exit"),
+     showVersion(__version__),
+    ),
     ('', 'quiet', False,
      _('be silent')),
     ('c', 'config_file', '',
         ui.config.read(["hob_private.conf"])
     ui.config.reads("[hob]\ntarget=current\n")
     _exts.setup(ui, cmds)
-    parser_args = dict(prog=__program__)
-    if Version(argparse.__version__) < "1.1":
-        parser_args["version"] = __version__
-    parser = argparse.ArgumentParser(**parser_args)
-    if "version" not in parser_args:
-        parser.add_argument("--version", action="version", version=__version__)
+    parser = argparse.ArgumentParser(prog=__program__)
     cmds.setup(parser)
     opts = parser.parse_args(args)
     cmds.loadconfig(ui.config, opts)