Adjust action commands (CLI)
* Provide 'input' property (aka parameters string) * Cut big string values in list output table Change-Id: I7229f6fcd8dddc8db220ebb42aad1baa3c03005a
This commit is contained in:
@@ -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', '<none>'),
|
||||
input,
|
||||
desc,
|
||||
', '.join(tags) or '<none>',
|
||||
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()
|
||||
|
@@ -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]
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user