Merge pull request #6327 from collin5/b6271

Add option for `--all` flag to `ps`
This commit is contained in:
Joffrey F 2018-11-15 14:32:58 -08:00 committed by GitHub
commit e86e10fb6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -694,6 +694,7 @@ class TopLevelCommand(object):
-q, --quiet Only display IDs
--services Display services
--filter KEY=VAL Filter services by a property
-a, --all Show all stopped containers (including those created by the run command)
"""
if options['--quiet'] and options['--services']:
raise UserError('--quiet and --services cannot be combined')
@ -706,10 +707,14 @@ class TopLevelCommand(object):
print('\n'.join(service.name for service in services))
return
containers = sorted(
self.project.containers(service_names=options['SERVICE'], stopped=True) +
self.project.containers(service_names=options['SERVICE'], one_off=OneOffFilter.only),
key=attrgetter('name'))
if options['--all']:
containers = sorted(self.project.containers(service_names=options['SERVICE'],
one_off=OneOffFilter.include, stopped=True))
else:
containers = sorted(
self.project.containers(service_names=options['SERVICE'], stopped=True) +
self.project.containers(service_names=options['SERVICE'], one_off=OneOffFilter.only),
key=attrgetter('name'))
if options['--quiet']:
for container in containers:

View File

@ -599,6 +599,14 @@ class CLITestCase(DockerClientTestCase):
assert 'with_build' in running.stdout
assert 'with_image' in running.stdout
def test_ps_all(self):
self.project.get_service('simple').create_container(one_off='blahblah')
result = self.dispatch(['ps'])
assert 'simple-composefile_simple_run_1' not in result.stdout
result2 = self.dispatch(['ps', '--all'])
assert 'simple-composefile_simple_run_1' in result2.stdout
def test_pull(self):
result = self.dispatch(['pull'])
assert 'Pulling simple' in result.stderr