1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-25 14:03:00 +00:00
kiwi-scp/kiwi_scp/subcommands/logs.py

40 lines
1.1 KiB
Python

# local
from ..subcommand import ServiceCommand
class LogsCommand(ServiceCommand):
"""kiwi logs"""
def __init__(self):
super().__init__(
'logs', num_projects=1, num_services='*',
action="Showing logs of",
description="Show logs of a project or service(s) inside a project"
)
# -f switch: Follow logs
self._sub_parser.add_argument(
'-f', '--follow', action='store_true',
help="output appended data as log grows"
)
def _run_services(self, runner, args, project, services):
# include timestamps
compose_cmd = ['logs', '-t']
# handle following the log output
if args.follow:
compose_cmd = [*compose_cmd, '-f', '--tail=10']
# append if one or more services are given
if services:
compose_cmd = [*compose_cmd, *args.services]
if args.follow:
project.compose_run(compose_cmd)
else:
# use 'less' viewer if output is static
project.compose_run_less(compose_cmd)
return True