summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2014-11-25 05:36:17 -0600
committerSol Jerome <sol.jerome@gmail.com>2014-11-25 05:36:17 -0600
commitea5e6b609ab72a7665ef18615b572e0fd99973c5 (patch)
tree503f425db291472d11f022c2854570bd68f5839a
parent461707505ec95c80c5324bc03a39413212bf83ee (diff)
parentb65b23f37a17b7d695b65e0b0d3c9ef8945856e9 (diff)
downloadbcfg2-ea5e6b609ab72a7665ef18615b572e0fd99973c5.tar.gz
bcfg2-ea5e6b609ab72a7665ef18615b572e0fd99973c5.tar.bz2
bcfg2-ea5e6b609ab72a7665ef18615b572e0fd99973c5.zip
Merge branch 'fix-version' of https://github.com/AlexanderS/bcfg2
-rw-r--r--src/lib/Bcfg2/Options/Parser.py11
-rw-r--r--testsuite/Testsrc/Testlib/TestOptions/TestOptions.py7
2 files changed, 16 insertions, 2 deletions
diff --git a/src/lib/Bcfg2/Options/Parser.py b/src/lib/Bcfg2/Options/Parser.py
index c846e8093..d146e3aa2 100644
--- a/src/lib/Bcfg2/Options/Parser.py
+++ b/src/lib/Bcfg2/Options/Parser.py
@@ -6,7 +6,7 @@ import sys
from Bcfg2.version import __version__
from Bcfg2.Compat import ConfigParser
-from Bcfg2.Options import Option, PathOption, BooleanOption, _debug
+from Bcfg2.Options import Option, PathOption, _debug
__all__ = ["setup", "OptionParserException", "Parser", "get_parser",
"new_parser"]
@@ -43,9 +43,16 @@ class Parser(argparse.ArgumentParser):
help="Path to configuration file",
default="/etc/bcfg2.conf")
+ #: Verbose version string that is printed if executed with --version
+ _version_string = "%s %s on Python %s" % (
+ os.path.basename(sys.argv[0]),
+ __version__,
+ ".".join(str(v) for v in sys.version_info[0:3]))
+
#: Builtin options that apply to all commands
options = [configfile,
- BooleanOption('--version', help="Print the version and exit"),
+ Option('--version', help="Print the version and exit",
+ action="version", version=_version_string),
Option('-E', '--encoding', metavar='<encoding>',
default='UTF-8', help="Encoding of config files",
cf=('components', 'encoding'))]
diff --git a/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py b/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py
index a2dc8ffe2..034a4580a 100644
--- a/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py
+++ b/testsuite/Testsrc/Testlib/TestOptions/TestOptions.py
@@ -185,6 +185,13 @@ class TestBasicOptions(OptionTestCase):
options = self._test_options(env={"TEST_PATH_OPTION": "/foo"})
self.assertEqual(options.test_path_option, "/foo")
+ def test_version(self):
+ """print version and exit on --version"""
+ self.assertRaises(
+ SystemExit,
+ self._test_options,
+ options=['--version'])
+
def test_set_boolean_in_cli(self):
"""set boolean options in CLI options."""
# passing the option yields the reverse of the default, no