Better ps output
This commit is contained in:
parent
bac37a19e3
commit
9cf1d232b2
3 changed files with 62 additions and 7 deletions
|
|
@ -10,6 +10,7 @@ from inspect import getdoc
|
|||
from .. import __version__
|
||||
from ..service_collection import ServiceCollection
|
||||
from .command import Command
|
||||
from .formatter import Formatter
|
||||
from .log_printer import LogPrinter
|
||||
|
||||
from docker.client import APIError
|
||||
|
|
@ -78,10 +79,30 @@ class TopLevelCommand(Command):
|
|||
"""
|
||||
List services and containers.
|
||||
|
||||
Usage: ps
|
||||
Usage: ps [options]
|
||||
|
||||
Options:
|
||||
-q Only display IDs
|
||||
"""
|
||||
for container in self._get_containers(all=False):
|
||||
print container.name
|
||||
if options['-q']:
|
||||
for container in self.service_collection.containers(all=True):
|
||||
print container.id
|
||||
else:
|
||||
headers = [
|
||||
'Name',
|
||||
'Command',
|
||||
'State',
|
||||
'Ports',
|
||||
]
|
||||
rows = []
|
||||
for container in self.service_collection.containers(all=True):
|
||||
rows.append([
|
||||
container.name,
|
||||
container.human_readable_command,
|
||||
container.human_readable_state,
|
||||
container.human_readable_ports,
|
||||
])
|
||||
print Formatter().table(headers, rows)
|
||||
|
||||
def run(self, options):
|
||||
"""
|
||||
|
|
@ -146,13 +167,10 @@ class TopLevelCommand(Command):
|
|||
|
||||
Usage: logs
|
||||
"""
|
||||
containers = self._get_containers(all=False)
|
||||
containers = self.service_collection.containers(all=False)
|
||||
print "Attaching to", list_containers(containers)
|
||||
LogPrinter(containers, attach_params={'logs': True}).run()
|
||||
|
||||
def _get_containers(self, all):
|
||||
return [c for s in self.service_collection for c in s.containers(all=all)]
|
||||
|
||||
|
||||
def list_containers(containers):
|
||||
return ", ".join(c.name for c in containers)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue