diff --git a/brewtils/decorators.py b/brewtils/decorators.py index 8d503bc8..8a89f874 100644 --- a/brewtils/decorators.py +++ b/brewtils/decorators.py @@ -45,7 +45,7 @@ def system(cls): def command(_wrapped=None, command_type='ACTION', output_type='STRING', schema=None, form=None, - template=None, icon_name=None): + template=None, icon_name=None, description=None): """Decorator that marks a function as a beer-garden command For example: @@ -64,17 +64,22 @@ def echo_json(self, message): :param form: A custom form definition. :param template: A custom template definition. :param icon_name: The icon name. Should be either a FontAwesome or a Glyphicon name. + :param description: The command description. Will override the function's docstring. :return: The decorated function. """ if _wrapped is None: return functools.partial(command, command_type=command_type, output_type=output_type, - schema=schema, form=form, template=template, icon_name=icon_name) + schema=schema, form=form, template=template, icon_name=icon_name, + description=description) generated_command = _generate_command_from_function(_wrapped) generated_command.command_type = command_type generated_command.output_type = output_type generated_command.icon_name = icon_name + if description: + generated_command.description = description + resolved_mod = _resolve_display_modifiers(_wrapped, generated_command.name, schema=schema, form=form, template=template) generated_command.schema = resolved_mod['schema'] diff --git a/test/decorators_test.py b/test/decorators_test.py index 9f22e528..53d74839 100644 --- a/test/decorators_test.py +++ b/test/decorators_test.py @@ -340,6 +340,17 @@ def foo(self): self.assertEqual(c.description, 'This is a doc') self.assertEqual(c.parameters, []) + @patch('brewtils.decorators._generate_params_from_function', Mock()) + def test_command_overwrite_description(self): + new_description = 'So descriptive' + + @command(description=new_description) + def foo(self): + """This is a doc""" + pass + + self.assertEqual(foo._command.description, new_description) + def test_command_generate_command_from_function_py2_compatibility(self): py2_code_mock = Mock(co_varnames=["var1"], co_argcount=1, spec=["co_varnames", "co_argcount"])