From 02c2945ecf1f52f78dda4fb7c70fffdfcaa155de Mon Sep 17 00:00:00 2001 From: ldericher Date: Mon, 10 Aug 2020 16:36:05 +0200 Subject: [PATCH] "logs" command with "-f" switch --- src/kiwi/subcommands/logs.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/kiwi/subcommands/logs.py b/src/kiwi/subcommands/logs.py index 699f297..5ee7935 100644 --- a/src/kiwi/subcommands/logs.py +++ b/src/kiwi/subcommands/logs.py @@ -1,3 +1,5 @@ +from ..core import Parser + from ._utils import SubCommand, DockerProgram @@ -5,12 +7,22 @@ class LogsCommand(SubCommand): def __init__(self): super().__init__( 'logs', - description="Show logs of a project" + description="Show logs of a project or service" + ) + + self.get_parser().add_argument( + '-f', '--follow', + action='store_true', + help="output appended data as log grows" ) def run(self): + args = ['logs', '-t'] + if Parser().get_args().follow: + args = [*args, '-f', '--tail=10'] + DockerProgram('docker-compose').run( - ['logs', '-tf', '--tail=10'], + args, cwd='hello-world.project', env={'COMPOSE_PROJECT_NAME': 'hello-world'} )