1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-04 17:43:01 +00:00
kiwi-scp/kiwi_scp/commands/cmd_logs.py

45 lines
1.2 KiB
Python
Raw Permalink Normal View History

2021-12-01 18:12:54 +00:00
from typing import List
import click
2021-12-02 16:19:14 +00:00
from .cmd import KiwiCommandType, KiwiCommand
2021-12-01 18:12:54 +00:00
from .decorators import kiwi_command
from ..executable import COMPOSE_EXE
2021-12-02 16:08:14 +00:00
from ..instance import Instance
from ..project import Project
from ..services import Services
2021-12-01 18:12:54 +00:00
@click.option(
"-f/-F",
"--follow/--no-follow",
help="output appended data as log grows",
)
@kiwi_command(
short_help="Show logs",
)
class LogsCommand(KiwiCommand):
"""Show logs of a project or service(s) inside a project"""
type = KiwiCommandType.SERVICES
enabled_only = True
@classmethod
def run_for_filtered_services(cls, instance: Instance, project: Project, services: Services,
new_service_names: List[str], follow: bool = None) -> None:
# include timestamps
compose_cmd = ["logs", "-t"]
# handle following the log output
if follow:
compose_cmd.extend(("-f", "--tail=10"))
compose_cmd.extend(services.names)
if follow:
COMPOSE_EXE.run(compose_cmd, **project.process_kwargs)
else:
# output is static, use pager
COMPOSE_EXE.run_with_pager(compose_cmd, **project.process_kwargs)