Shipyard CLI guard empty directory

Guards against creating configdocs using a directory with
no .yaml files present.

This change also orders the result of shipyard get actions to
sort the actions chronologically so that the newest actions
should always appear at the bottom of the list when using the
default cli output-format

Closes #21

Change-Id: I47dfd730f80dddd88a4b1f38b52f777a56ece774
This commit is contained in:
Bryan Strassner 2018-02-24 13:51:41 -06:00 committed by Anthony Lin
parent 78b82c76a8
commit f629ee14cc
4 changed files with 22 additions and 3 deletions

View File

@ -124,7 +124,8 @@ def gen_action_table(action_list):
actions = format_utils.table_factory(
field_names=['Name', 'Action', 'Lifecycle'])
if action_list:
for action in action_list:
# sort by id, which is ULID - chronological.
for action in sorted(action_list, key=lambda k: k['id']):
actions.add_row([
action.get('name'), 'action/{}'.format(action.get('id')),
action.get('action_lifecycle')

View File

@ -139,8 +139,9 @@ def create_configdocs(ctx, collection, filename, directory, append,
[os.path.join(dir, each) for each in os.listdir(dir)
if each.endswith('.yaml')])
if filename is None:
ctx.fail('The directory does not contain any YAML files.'
if not filename:
# None or empty list should raise this error
ctx.fail('The directory does not contain any YAML files. '
'Please enter one or more YAML files or a '
'directory that contains one or more YAML files.')

View File

@ -0,0 +1 @@
This is not a .yaml file.

View File

@ -84,6 +84,22 @@ def test_create_configdocs_directory():
mock_method.assert_called_once_with(ANY, collection, 'append', ANY, ANY)
def test_create_configdocs_directory_empty():
"""test create configdocs with empty directory"""
collection = 'design'
dir1 = 'shipyard_client/tests/unit/cli/create/no_yaml_dir/'
runner = CliRunner()
with patch.object(CreateConfigdocs, 'invoke_and_return_resp') as _method:
result = runner.invoke(shipyard, [
auth_vars, 'create', 'configdocs', collection,
'--directory=' + dir1
])
_method.assert_not_called()
assert b'directory does not contain any YAML files' in result.output_bytes
def test_create_configdocs_multi_directory():
"""test create configdocs with multiple directories"""