mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-24 13:43:01 +00:00
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from typing import List
|
|
|
|
import click
|
|
|
|
from .cmd import KiwiCommandType, KiwiCommand
|
|
from .decorators import kiwi_command
|
|
from ..executable import COMPOSE_EXE
|
|
from ..instance import Instance
|
|
from ..project import Project
|
|
from ..services import Services
|
|
|
|
|
|
@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)
|