Repository: 3YOURMIND/django-migration-linter

Issue:
Add --version option
Pretty straightforward. Have a `--version` that prints the current version of the linter.

Discussion:

Patch:
diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py
index f9c0ab1..03c2054 100644
--- a/django_migration_linter/migration_linter.py
+++ b/django_migration_linter/migration_linter.py
@@ -20,7 +20,7 @@ from subprocess import Popen, PIPE
 import sys
 
 from .cache import Cache
-from .constants import DEFAULT_CACHE_PATH, MIGRATION_FOLDER_NAME
+from .constants import DEFAULT_CACHE_PATH, MIGRATION_FOLDER_NAME, __version__
 from .migration import Migration
 from .utils import is_directory, is_django_project, clean_bytes_to_str
 from .sql_analyser import analyse_sql_statements
@@ -287,6 +287,9 @@ def _main():
         action="store_true",
         help="print more information during execution",
     )
+    parser.add_argument(
+        "--version", "-V", action="version", version="%(prog)s {}".format(__version__)
+    )
     parser.add_argument(
         "--database",
         type=str,


Test patch:
diff --git a/tests/functional/test_cmd_line_call.py b/tests/functional/test_cmd_line_call.py
index a2861fa..47d7944 100644
--- a/tests/functional/test_cmd_line_call.py
+++ b/tests/functional/test_cmd_line_call.py
@@ -16,7 +16,7 @@ import os
 import shutil
 import unittest
 from subprocess import Popen, PIPE
-from django_migration_linter import utils, DEFAULT_CACHE_PATH
+from django_migration_linter import utils, DEFAULT_CACHE_PATH, constants
 from tests import fixtures
 import sys
 
@@ -274,3 +274,25 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
         self.assertTrue(lines[0].endswith('ERR'))
         self.assertTrue(lines[2].endswith('OK'))
         self.assertTrue(lines[3].startswith('*** Summary'))
+
+
+class VersionOptionLinterFromCommandLineTest(CallLinterFromCommandLineTest):
+    def test_call_with_version_option(self):
+        cmd = "{} --version".format(self.linter_exec)
+        process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
+        process.wait()
+        self.assertEqual(process.returncode, 0)
+        process_read_stream = process.stderr if sys.version_info.major == 2 else process.stdout
+        lines = list(map(utils.clean_bytes_to_str, process_read_stream.readlines()))
+        self.assertEqual(len(lines), 1)
+        self.assertEqual(lines[0], "django-migration-linter {}".format(constants.__version__))
+
+    def test_call_with_short_version_option(self):
+        cmd = "{} -V".format(self.linter_exec)
+        process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
+        process.wait()
+        self.assertEqual(process.returncode, 0)
+        process_read_stream = process.stderr if sys.version_info.major == 2 else process.stdout
+        lines = list(map(utils.clean_bytes_to_str, process_read_stream.readlines()))
+        self.assertEqual(len(lines), 1)
+        self.assertEqual(lines[0], "django-migration-linter {}".format(constants.__version__))