diff --git a/cli/dcoscli/task/main.py b/cli/dcoscli/task/main.py index 7883c7f..279e4f9 100644 --- a/cli/dcoscli/task/main.py +++ b/cli/dcoscli/task/main.py @@ -181,12 +181,20 @@ def _ls(task, path, long_, completed): path = path[1:] dcos_client = mesos.DCOSClient() - task_obj = mesos.get_master(dcos_client).task( - fltr=task, completed=completed) - dir_ = posixpath.join(task_obj.directory(), path) + task_objects = mesos.get_master(dcos_client).tasks( + fltr=task, + completed=completed) + + if len(task_objects) == 0: + raise DCOSException( + 'Cannot find a task with ID containing "{}"'.format(task)) try: - files = dcos_client.browse(task_obj.slave(), dir_) + all_files = [] + for task_obj in task_objects: + dir_ = posixpath.join(task_obj.directory(), path) + all_files += [ + (task_obj['id'], dcos_client.browse(task_obj.slave(), dir_))] except DCOSHTTPException as e: if e.response.status_code == 404: raise DCOSException( @@ -194,7 +202,10 @@ def _ls(task, path, long_, completed): else: raise - if files: + add_header = len(all_files) > 1 + for (task_id, files) in all_files: + if add_header: + emitter.publish('===> {} <==='.format(task_id)) if long_: emitter.publish(tables.ls_long_table(files)) else: diff --git a/cli/tests/integrations/test_task.py b/cli/tests/integrations/test_task.py index bd63a4f..baef6b7 100644 --- a/cli/tests/integrations/test_task.py +++ b/cli/tests/integrations/test_task.py @@ -233,13 +233,18 @@ def test_ls(): def test_ls_multiple_tasks(): + ls_line = 'stderr stderr.logrotate.conf stdout stdout.logrotate.conf' returncode, stdout, stderr = exec_command( ['dcos', 'task', 'ls', 'test-app']) + lines = stdout.decode('utf-8').split('\n') + assert len(lines) == 5 + assert re.match('===>.*<===', lines[0]) + assert re.match(ls_line, lines[1]) + assert re.match('===>.*<===', lines[2]) + assert re.match(ls_line, lines[3]) - assert returncode == 1 - assert stdout == b'' - assert stderr.startswith(b'There are multiple tasks with ID matching ' - b'[test-app]. Please choose one:\n\t') + returncode, stdout, stderr = exec_command( + ['dcos', 'task', 'ls', 'test-app']) def test_ls_long():