* namcap --version or namcap -v prints the version and exits * Update manpage with the the new option * Add a test that the manpage version is the same as the program version --- Namcap/tests/test_version.py | 37 +++++++++++++++++++++++++++++++++++++ namcap.1 | 3 +++ namcap.py | 10 ++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Namcap/tests/test_version.py diff --git a/Namcap/tests/test_version.py b/Namcap/tests/test_version.py new file mode 100644 index 0000000..3a7e685 --- /dev/null +++ b/Namcap/tests/test_version.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# +# namcap tests - tests for the version module +# Copyright (C) 2015 Rikard Falkeborn <rikard.falkeborn@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA +# + +import os +import unittest +import re +import Namcap.version + + +class VersionTests(unittest.TestCase): + def test_manpage(self): + ''' Test that the manpage and program has the same version.''' + here = os.path.dirname(os.path.realpath(__file__)) + with open(os.path.join(here, '..', '..', 'namcap.1')) as f: + first_line = f.readline() + match = re.search('"namcap (.*?)"', first_line) + self.assertEqual(match.group(1), Namcap.version.get_version()) + +# vim: set ts=4 sw=4 noet: diff --git a/namcap.1 b/namcap.1 index 70bb21c..a17bdf6 100644 --- a/namcap.1 +++ b/namcap.1 @@ -26,6 +26,9 @@ displays easily parseable namcap tags instead of the normal human readable descr only apply RULELIST rules to the package .IP RULELIST is a comma-separated list of rule names +.TP +.B "\-v, \-\-version" +print version and exit .SH RULES .TP .B arrays diff --git a/namcap.py b/namcap.py index cca5dd6..b62a2fa 100755 --- a/namcap.py +++ b/namcap.py @@ -31,6 +31,7 @@ import types import Namcap.depends import Namcap.tags +import Namcap.version # Functions def get_modules(): @@ -49,6 +50,7 @@ def usage(): print(" -e rulelist, --exclude=rulelist : don't apply RULELIST rules to the package") print(" -r rulelist, --rules=rulelist : only apply RULELIST rules to the package") print(" -t tags : use a custom tag file") + print(" -v version : print version and exit") sys.exit(2) @@ -171,9 +173,9 @@ filename = None # get our options and process them try: - optlist, args = getopt.getopt(sys.argv[1:], "ihmr:e:t:L", + optlist, args = getopt.getopt(sys.argv[1:], "ihmr:e:t:Lv", ["info", "help", "machine-readable", "rules=", - "exclude=", "tags=", "list"]) + "exclude=", "tags=", "list", "version"]) except getopt.GetoptError: usage() @@ -222,6 +224,10 @@ for i, k in optlist: if i in ('-t', '--tags'): filename = k + if i in ('-v', '--version'): + print(Namcap.version.get_version()) + sys.exit(0) + # If there are no args, print usage if (args == []): usage() -- 2.4.6