From a309bf7484bb8fea458eb09ee2b615c2011b05f8 Mon Sep 17 00:00:00 2001 From: CLiu13 Date: Sat, 19 Jan 2019 16:29:37 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20`-v`=20to=20show=20current=20?= =?UTF-8?q?moban=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://github.com/moremoban/moban/issues/107 --- .moban.cd/changelog.yml | 6 ++++++ CHANGELOG.rst | 9 +++++++++ moban/constants.py | 1 + moban/main.py | 7 +++++++ tests/integration_tests/test_command_line_options.py | 9 +++++++++ 5 files changed, 32 insertions(+) diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 2f28e686..519d782c 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,12 @@ name: moban organisation: moremoban releases: +- changes: + - action: Updated + details: + - "`#107`: Add -v to show current moban version" + date: 22-1-2019 + version: 0.4.0 - changes: - action: Updated details: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ac728d82..1239b428 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,15 @@ Change log ================================================================================ +0.4.0 - 22-1-2019 +-------------------------------------------------------------------------------- + +Updated +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +#. `#107 `_: Add -v to show + current moban version + 0.3.9 - 18-1-2019 -------------------------------------------------------------------------------- diff --git a/moban/constants.py b/moban/constants.py index b17eeaca..bed9ab9e 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -29,6 +29,7 @@ LABEL_OVERRIDES = "overrides" LABEL_MOBANFILE = "mobanfile" LABEL_FORCE = "force" +LABEL_VERSION = "version" DEFAULT_CONFIGURATION_DIRNAME = ".moban.cd" diff --git a/moban/main.py b/moban/main.py index f811efa0..5429edd2 100644 --- a/moban/main.py +++ b/moban/main.py @@ -18,6 +18,7 @@ from moban import plugins from moban.utils import merge, open_yaml from moban.hashstore import HASH_STORE +from moban._version import __version__ def main(): @@ -115,6 +116,12 @@ def create_parser(): nargs="?", help="string templates", ) + parser.add_argument( + "-v", + "--%s" % constants.LABEL_VERSION, + action="version", + version="%(prog)s {v}".format(v=__version__) + ) return parser diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 666fe3f8..d8bf7fd1 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -408,3 +408,12 @@ def test_mako_option(self, fake_template_doer): def tearDown(self): os.unlink(self.config_file) + + +@raises(SystemExit) +def test_version_option(): + test_args = ["moban", "-v"] + with patch.object(sys, "argv", test_args): + from moban.main import main + + main()