Repository: coala/coala

Issue:
ConsoleInteraction: Remove unnecessary parameters from show_bear
<!-- Hello! If you're filing a bug, please include every step so as to help us reproduce it on our machines. If you're unsure about how to file an issue, use the issue template. If you need any help regarding usage of coala, check out the documentation or hit us up on chat. You can ignore or delete this text, it is commented and won't appear when the issue is submitted or previewed.

Chat: https://coala.io/chat
Issue Template: https://github.com/coala/coala/blob/master/CONTRIBUTING.rst#filing-issues
Documentation: https://docs.coala.io
-->


From the comment at https://github.com/coala/coala/pull/4817#discussion_r148143217 in 
```
def show_bear(bear,
              show_description,
              show_params,
              console_printer,
              args):
```
parameters `show_description` and `show_params` are redundent as both of these can be easily derived from `args`.
We need to clean up these.


Discussion:
Blocked until https://github.com/coala/coala/pull/4817 is merged.

EDIT:
CC @Makman2 @Asalle
[GitMate.io](https://gitmate.io) thinks possibly duplicate or related issues are #4306 (Implement Security aspect), and #4489 (This is a test issue about a typo).
Can I take this if no one is working on it?
@alphadose Are you still working on this ? If not, we can reassign this to @anuyog1004 
@shreyans800755 yes I am working on this. I started working only after your PR got merged. Been about 3 days I guess :3
No problem. @anuyog1004, please find some other issue to work on . This is already taken at the moment.
@alphadose Are you still working on this?
@shreyateeza  my work is finished , just waiting for review :P
c.f. my rants at

https://github.com/coala/coala/pull/4948#issuecomment-352404883
https://github.com/coala/coala/pull/4948#discussion_r157926973

If you cant improve existing functions without breaking them, create a new function and deprecate the old one.  This is why designing extensibility at the beginning is so important.

Resolving patch:
diff --git a/coalib/misc/DeprecationUtilities.py b/coalib/misc/DeprecationUtilities.py
new file mode 100644
--- /dev/null
+++ b/coalib/misc/DeprecationUtilities.py
@@ -0,0 +1,28 @@
+import logging
+
+
+def check_deprecation(param_list):
+    """
+    Shows a deprecation warning message if the parameters
+    passed are not ``None``.
+
+    :param param_list:
+        A dictionary of parameters with their names mapped
+        to their values being checked for deprecation.
+
+    >>> from testfixtures import LogCapture
+    >>> from collections import OrderedDict
+    >>> param_list = OrderedDict([('foo', None),
+    ...                           ('bar', 'Random'),
+    ...                           ('baz', 1773)])
+    >>> with LogCapture() as capture:
+    ...     check_deprecation(param_list)
+    ...     print(capture)
+    root WARNING
+      bar parameter is deprecated
+    root WARNING
+      baz parameter is deprecated
+    """
+    for param_name, param_value in param_list.items():
+        if param_value is not None:
+            logging.warning('{} parameter is deprecated'.format(param_name))
diff --git a/coalib/output/ConsoleInteraction.py b/coalib/output/ConsoleInteraction.py
--- a/coalib/output/ConsoleInteraction.py
+++ b/coalib/output/ConsoleInteraction.py
@@ -2,6 +2,7 @@
 import logging
 import platform
 import os
+from collections import OrderedDict
 
 from termcolor import colored
 
@@ -13,6 +14,7 @@
 
 from coalib.misc.DictUtilities import inverse_dicts
 from coalib.misc.Exceptions import log_exception
+from coalib.misc.DeprecationUtilities import check_deprecation
 from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
 from coalib.results.Result import Result
 from coalib.results.result_actions.ApplyPatchAction import ApplyPatchAction
@@ -866,8 +868,8 @@ def show_bear(bear,
     Displays all information about a bear.
 
     :param bear:             The bear to be displayed.
-    :param show_description: True if the main description should be shown.
-    :param show_params:      True if the details should be shown.
+    :param show_description: This parameter is deprecated.
+    :param show_params:      This parameter is deprecated.
     :param console_printer:  Object to print messages on the console.
     :param args:             Args passed to coala command.
     """
@@ -875,6 +877,10 @@ def show_bear(bear,
 
     metadata = bear.get_metadata()
 
+    check_deprecation(OrderedDict([
+        ('show_description', show_description),
+        ('show_params', show_params)]))
+
     if show_description:
         console_printer.print(
             '  ' + metadata.desc.replace('\n', '\n  '))
@@ -927,13 +933,15 @@ def print_bears(bears,
 
     :param bears:            It's a dictionary with bears as keys and list of
                              sections containing those bears as values.
-    :param show_description: True if the main description of the bears should
-                             be shown.
-    :param show_params:      True if the parameters and their description
-                             should be shown.
+    :param show_description: This parameter is deprecated.
+    :param show_params:      This parameter is deprecated.
     :param console_printer:  Object to print messages on the console.
     :param args:             Args passed to coala command.
     """
+    check_deprecation(OrderedDict([
+        ('show_description', show_description),
+        ('show_params', show_params)]))
+
     if not bears and not (args and args.json):
         console_printer.print('No bears to show. Did you forget to install '
                               'the `coala-bears` package? Try `pip3 install '
@@ -984,10 +992,8 @@ def show_bears(local_bears,
                              as keys and bear list as values.
     :param global_bears:     Dictionary of global bears with section
                              names as keys and bear list as values.
-    :param show_description: True if the main description of the bears should
-                             be shown.
-    :param show_params:      True if the parameters and their description
-                             should be shown.
+    :param show_description: This parameter is deprecated.
+    :param show_params:      This parameter is deprecated.
     :param console_printer:  Object to print messages on the console.
     :param args:             Args passed to coala command.
     """


Test patch:
diff --git a/tests/output/ConsoleInteractionTest.py b/tests/output/ConsoleInteractionTest.py
--- a/tests/output/ConsoleInteractionTest.py
+++ b/tests/output/ConsoleInteractionTest.py
@@ -14,6 +14,7 @@
 from coalib import coala
 from coala_utils.ContextManagers import (
     make_temp, retrieve_stdout, simulate_console_inputs)
+from coala_utils.decorators import check_logs
 from coalib.output.ConsoleInteraction import (
     acquire_actions_and_apply, acquire_settings, get_action_info, nothing_done,
     print_affected_files, print_result, print_results,
@@ -869,12 +870,21 @@ class ShowBearsTest(unittest.TestCase):
     def setUp(self):
         self.console_printer = ConsolePrinter(print_colored=False)
 
+    deprecation_messages = [('root',
+                             'WARNING',
+                             'show_description parameter is deprecated'),
+                            ('root',
+                             'WARNING',
+                             'show_params parameter is deprecated')]
+
+    @check_logs(*deprecation_messages)
     def test_show_bear_minimal(self):
         with retrieve_stdout() as stdout:
             show_bear(
                 SomelocalBear, False, False, self.console_printer)
             self.assertEqual(stdout.getvalue(), 'SomelocalBear\n')
 
+    @check_logs(*deprecation_messages)
     def test_show_bear_desc_only(self):
         with retrieve_stdout() as stdout:
             show_bear(
@@ -883,6 +893,7 @@ def test_show_bear_desc_only(self):
                 stdout.getvalue(),
                 'SomelocalBear\n  Some local-bear Description.\n\n')
 
+    @check_logs(*deprecation_messages)
     def test_show_bear_details_only(self):
         with retrieve_stdout() as stdout:
             show_bear(
@@ -900,6 +911,7 @@ def test_show_bear_details_only(self):
                              'can fix.\n\n  Path:\n   ' +
                              repr(SomelocalBear.source_location) + '\n\n')
 
+    @check_logs(*deprecation_messages)
     def test_show_bear_long_without_content(self):
         with retrieve_stdout() as stdout:
             show_bear(
@@ -918,6 +930,7 @@ def test_show_bear_long_without_content(self):
                              'can fix.\n\n  Path:\n   ' +
                              repr(SomelocalBear.source_location) + '\n\n')
 
+    @check_logs(*deprecation_messages)
     def test_show_bear_with_content(self):
         with retrieve_stdout() as stdout:
             show_bear(TestBear, True, True, self.console_printer)
@@ -937,9 +950,9 @@ def test_show_bear_with_content(self):
                              '  Can fix:\n   * Formatting\n\n  Path:\n   ' +
                              repr(TestBear.source_location) + '\n\n')
 
+    @check_logs(*deprecation_messages)
     def test_show_bear_settings_only(self):
         with retrieve_stdout() as stdout:
-            from coalib.parsing.DefaultArgParser import default_arg_parser
             args = default_arg_parser().parse_args(['--show-settings'])
             show_bear(TestBear, False, False, self.console_printer, args)
             self.assertEqual(stdout.getvalue(),
@@ -950,17 +963,20 @@ def test_show_bear_settings_only(self):
                              '   * setting2: Optional Setting. ('
                              "Optional, defaults to 'None'.)\n\n")
 
+    @check_logs(*deprecation_messages)
     def test_show_bears_empty(self):
         with retrieve_stdout() as stdout:
             show_bears({}, {}, True, True, self.console_printer)
             self.assertIn('No bears to show.', stdout.getvalue())
 
+    @check_logs(*deprecation_messages)
     def test_show_bears_with_json(self):
         args = default_arg_parser().parse_args(['--json'])
         with retrieve_stdout() as stdout:
             show_bears({}, {}, True, True, self.console_printer, args)
             self.assertEqual('{\n  "bears": []\n}\n', stdout.getvalue())
 
+    @check_logs(*deprecation_messages)
     @patch('coalib.output.ConsoleInteraction.show_bear')
     def test_show_bears(self, show_bear):
         local_bears = OrderedDict([('default', [SomelocalBear]),
@@ -972,6 +988,7 @@ def test_show_bears(self, show_bear):
                                           self.console_printer,
                                           None)
 
+    @check_logs(*(deprecation_messages*5))
     def test_show_bears_sorted(self):
         local_bears = OrderedDict([('default', [SomelocalBear]),
                                    ('test', [aSomelocalBear])])