summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRikard Falkeborn <rikard.falkeborn@gmail.com>2015-07-16 09:15:08 +0200
committerKyle Keen <keenerd@gmail.com>2016-01-31 15:57:33 -0500
commitd18bb2c70397fd5fbf5d234c89c09a2f1150a9c2 (patch)
tree6e8ede02534a274fa76b4c5e99b29769dac2458b
parent079261be888e112df780ec71229a1894e33084ff (diff)
downloadnamcap-d18bb2c70397fd5fbf5d234c89c09a2f1150a9c2.tar.gz
namcap-d18bb2c70397fd5fbf5d234c89c09a2f1150a9c2.zip
Add --version argument
* 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 Signed-off-by: Kyle Keen <keenerd@gmail.com>
-rw-r--r--Namcap/tests/test_version.py37
-rw-r--r--namcap.13
-rwxr-xr-xnamcap.py10
3 files changed, 48 insertions, 2 deletions
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 378e7ae..ace6fa6 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()