mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-12-24 18:22:59 +00:00
"kiwi logs"
This commit is contained in:
parent
d197398c3b
commit
15f0ac30b5
1 changed files with 42 additions and 0 deletions
42
kiwi_scp/commands/cmd_logs.py
Normal file
42
kiwi_scp/commands/cmd_logs.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from typing import List
|
||||
|
||||
import click
|
||||
|
||||
from .cli import KiwiCommand, KiwiCommandType
|
||||
from .decorators import kiwi_command
|
||||
from ..executable import COMPOSE_EXE
|
||||
from ..instance import Instance, Project, 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)
|
Loading…
Reference in a new issue