Skip to content

Commit

Permalink
Adding description kwarg to command decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
hazmat345 committed Feb 22, 2018
1 parent 739216e commit 331152e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions brewtils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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']
Expand Down
11 changes: 11 additions & 0 deletions test/decorators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 331152e

Please sign in to comment.