Repository: melexis/warnings-plugin

Issue:
Return code of main() could/should be number of warnings
When count of warnings is not within limit min/max, the return code of main() could be the number of actual warnings found. This way programs can take the return value from shell and do something with it.

Discussion:

Patch:
diff --git a/README.rst b/README.rst
index 7b37e9c..6c66f05 100644
--- a/README.rst
+++ b/README.rst
@@ -10,22 +10,10 @@
     :target: https://codecov.io/gh/melexis/warnings-plugin
     :alt: Code Coverage
 
-.. image:: https://codeclimate.com/github/melexis/warnings-plugin/badges/gpa.svg
-    :target: https://codeclimate.com/github/melexis/warnings-plugin
-    :alt: Code Climate Status
-
-.. image:: https://codeclimate.com/github/melexis/warnings-plugin/badges/issue_count.svg
-    :target: https://codeclimate.com/github/melexis/warnings-plugin
-    :alt: Issue Count
-
 .. image:: https://requires.io/github/melexis/warnings-plugin/requirements.svg?branch=master
     :target: https://requires.io/github/melexis/warnings-plugin/requirements/?branch=master
     :alt: Requirements Status
 
-.. image:: https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat
-    :target: https://github.com/melexis/warnings-plugin/issues
-    :alt: Contributions welcome
-
 
 ============================
 Command line warnings-plugin
@@ -99,6 +87,11 @@ that case command will look like:
 
 Help prints all currently supported commands and their usages.
 
+The command returns (shell $? variable):
+
+- value 0 when the number of counted warnings is within the supplied minimum and maximum limits: ok,
+- number of counted warnings (positive) when the counter number is not within those limit.
+
 ----------------------------
 Parse for Sphinx warnings
 ----------------------------
diff --git a/docs/conf.py b/docs/conf.py
index 02a5c31..1f6c773 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -62,8 +62,8 @@ napoleon_use_param = False
 if 'nt' in os.name:
     plantuml_path = subprocess.check_output(["where", "/F", "plantuml.jar"])
     if not plantuml_path :
-        print("Can't find 'plantuml.jar' file.")
-        print("You need to add path to 'plantuml.jar' file to your PATH variable.")
+        print "Can't find 'plantuml.jar' file."
+        print "You need to add path to 'plantuml.jar' file to your PATH variable."
         sys.exit(os.strerror(errno.EPERM))
     plantuml = plantuml_path.decode("utf-8")
     plantuml = plantuml.rstrip('\n\r')
@@ -73,8 +73,8 @@ if 'nt' in os.name:
 else:
     plantuml_path = subprocess.check_output(["whereis", "-u", "plantuml"])
     if not plantuml_path :
-        print("Can't find 'plantuml.jar' file.")
-        print("You need to add path to 'plantuml.jar' file to your PATH variable.")
+        print "Can't find 'plantuml.jar' file."
+        print "You need to add path to 'plantuml.jar' file to your PATH variable."
         sys.exit(os.strerror(errno.EPERM))
 
 
diff --git a/src/mlx/warnings.py b/src/mlx/warnings.py
index 70a8474..ccbb45a 100644
--- a/src/mlx/warnings.py
+++ b/src/mlx/warnings.py
@@ -94,14 +94,14 @@ class WarningsChecker(object):
         ''' Function for checking whether the warning count is within the configured limits
 
         Returns:
-            int: 0 if the amount of warnings is within limits. 1 otherwise
+            int: 0 if the amount of warnings is within limits. the count of warnings otherwise
         '''
         if self.count > self.warn_max:
             print("Number of warnings ({count}) is higher than the maximum limit ({max}). Returning error code 1.".format(count=self.count, max=self.warn_max))
-            return 1
+            return self.count
         elif self.count < self.warn_min:
             print("Number of warnings ({count}) is lower than the minimum limit ({min}). Returning error code 1.".format(count=self.count, min=self.warn_min))
-            return 1
+            return self.count
         else:
             print("Number of warnings ({count}) is between limits {min} and {max}. Well done.".format(count=self.count, min=self.warn_min, max=self.warn_max))
             return 0


Test patch:
diff --git a/tests/test_limits.py b/tests/test_limits.py
index 7a6b1c9..9e477a8 100644
--- a/tests/test_limits.py
+++ b/tests/test_limits.py
@@ -45,7 +45,7 @@ class TestLimits(TestCase):
         warnings.check('testfile.c:12: warning: group test: ignoring title "Some test functions" that does not match old title "Some freaky test functions"')
         self.assertEqual(warnings.return_count(), 2)
         warnings.set_maximum(1)
-        self.assertEqual(warnings.return_check_limits(), 1)
+        self.assertEqual(warnings.return_check_limits(), 2)
         warnings.set_maximum(2)
         self.assertEqual(warnings.return_check_limits(), 0)
 
@@ -56,7 +56,7 @@ class TestLimits(TestCase):
         warnings.check('testfile.c:6: warning: group test: ignoring title "Some test functions" that does not match old title "Some freaky test functions"')
         self.assertEqual(warnings.return_count(), 2)
         # default behavior
-        self.assertEqual(warnings.return_check_limits(), 1)
+        self.assertEqual(warnings.return_check_limits(), 2)
 
         # to set minimum we need to make maximum higher
         warnings.set_maximum(10)
@@ -64,7 +64,7 @@ class TestLimits(TestCase):
             if x <= 3:
                 self.assertEqual(warnings.return_check_limits(), 0)
             else:
-                self.assertEqual(warnings.return_check_limits(), 1)
+                self.assertEqual(warnings.return_check_limits(), 2)
             warnings.set_minimum(x)