Repository: peterbe/hashin

Issue:
hashin --version should say what version hashin is
Title says it all. 

Discussion:

Patch:
diff --git a/README.rst b/README.rst
index 984d968..15310ff 100644
--- a/README.rst
+++ b/README.rst
@@ -185,6 +185,11 @@ put it directly into ``pip``.
 Version History
 ===============
 
+0.11.1
+  * Ability to run ``hashin --version`` to see what version of hashin is
+    installed.
+    See https://github.com/peterbe/hashin/issues/41
+
 0.11.0
   * Cope with leading zeros in version numbers when figuring out what
     the latest version is.
diff --git a/hashin.py b/hashin.py
index 6d05a41..3c9159c 100755
--- a/hashin.py
+++ b/hashin.py
@@ -64,6 +64,13 @@ parser.add_argument(
     action='append',
     default=[],
 )
+parser.add_argument(
+    '--version',
+    help='Version of hashin',
+    action='store_true',
+    default=False,
+)
+
 
 major_pip_version = int(pip.__version__.split('.')[0])
 if major_pip_version < 8:
@@ -408,6 +415,13 @@ def get_package_hashes(
 
 
 def main():
+    if '--version' in sys.argv[1:]:
+        # Can't be part of argparse because the 'packages' is mandatory
+        # print out the version of self
+        import pkg_resources
+        print(pkg_resources.get_distribution('hashin').version)
+        return 0
+
     args = parser.parse_args()
 
     return run(


Test patch:
diff --git a/tests/test_arg_parse.py b/tests/test_arg_parse.py
index e570635..cfdacdc 100644
--- a/tests/test_arg_parse.py
+++ b/tests/test_arg_parse.py
@@ -19,6 +19,7 @@ def test_everything():
         python_version=['3.5'],
         requirements_file='reqs.txt',
         verbose=True,
+        version=False,
     )
     eq_(args, (expected, []))
 
@@ -37,6 +38,7 @@ def test_everything_long():
         python_version=['3.5'],
         requirements_file='reqs.txt',
         verbose=True,
+        version=False,
     )
     eq_(args, (expected, []))
 
@@ -49,5 +51,6 @@ def test_minimal():
         python_version=[],
         requirements_file='requirements.txt',
         verbose=False,
+        version=False,
     )
     eq_(args, (expected, []))