diff --git a/mistralclient/commands/v2/actions.py b/mistralclient/commands/v2/actions.py index 2d93c8f4..3daa4c13 100644 --- a/mistralclient/commands/v2/actions.py +++ b/mistralclient/commands/v2/actions.py @@ -26,10 +26,22 @@ from mistralclient.commands.v2 import base LOG = logging.getLogger(__name__) -def format(action=None): +def _cut(string, length=25): + if string and len(string) > length: + return "%s..." % string[:length] + else: + return string + + +def format_list(action=None): + return format(action, lister=True) + + +def format(action=None, lister=False): columns = ( 'Name', 'Is system', + 'Input', 'Description', 'Tags', 'Created at', @@ -38,11 +50,14 @@ def format(action=None): if action: tags = getattr(action, 'tags', None) or [] + input = action.input if not lister else _cut(action.input) + desc = action.description if not lister else _cut(action.description) data = ( action.name, action.is_system, - getattr(action, 'description', ''), + input, + desc, ', '.join(tags) or '', action.created_at, ) @@ -61,7 +76,7 @@ class List(base.MistralLister): """List all actions.""" def _get_format_function(self): - return format + return format_list def _get_resources(self, parsed_args): return actions.ActionManager(self.app.client).list() diff --git a/mistralclient/tests/unit/v2/test_cli_actions.py b/mistralclient/tests/unit/v2/test_cli_actions.py index b5898d80..64d7cd92 100644 --- a/mistralclient/tests/unit/v2/test_cli_actions.py +++ b/mistralclient/tests/unit/v2/test_cli_actions.py @@ -25,6 +25,7 @@ from mistralclient.api.v2 import actions ACTION_DICT = { 'name': 'a', 'is_system': True, + 'input': "param1", 'description': 'My cool action', 'tags': ['test'], 'created_at': '1', @@ -56,7 +57,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.Create, app_args=['1.txt']) self.assertEqual( - [('a', True, 'My cool action', 'test', '1', '1')], + [('a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -68,7 +69,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.Update, app_args=['my_action.yaml']) self.assertEqual( - [('a', True, 'My cool action', 'test', '1', '1')], + [('a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -79,7 +80,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.List) self.assertEqual( - [('a', True, 'My cool action', 'test', '1', '1')], + [('a', True, "param1", 'My cool action', 'test', '1', '1')], result[1] ) @@ -90,7 +91,7 @@ class TestCLIActionsV2(base.BaseCommandTest): result = self.call(action_cmd.Get, app_args=['name']) self.assertEqual( - ('a', True, 'My cool action', 'test', '1', '1'), + ('a', True, "param1", 'My cool action', 'test', '1', '1'), result[1] )