diff --git a/example/hello-world.project/docker-compose.yml b/example/hello-world.project/docker-compose.yml index e8398b7..f49c63f 100644 --- a/example/hello-world.project/docker-compose.yml +++ b/example/hello-world.project/docker-compose.yml @@ -12,4 +12,7 @@ networks: services: hello-world: image: alpine:latest - command: sh -c 'while :; do echo Hello World "$$RANDOM"; sleep 10; done' + command: sh -c 'LOOP=1; while :; do echo Hello World "$$LOOP"; LOOP=$$(($$LOOP + 1)); sleep 10; done' + foo-bar: + image: alpine:latest + command: sh -c 'LOOP=1; while :; do echo Foo Bar "$$LOOP"; LOOP=$$(($$LOOP + 1)); sleep 20; done' diff --git a/example/kiwi b/example/kiwi new file mode 120000 index 0000000..d7c36e5 --- /dev/null +++ b/example/kiwi @@ -0,0 +1 @@ +../src/kiwi-config.py \ No newline at end of file diff --git a/src/kiwi/subcommands/_utils.py b/src/kiwi/subcommands/_utils.py index e0e4f77..47458ab 100644 --- a/src/kiwi/subcommands/_utils.py +++ b/src/kiwi/subcommands/_utils.py @@ -28,18 +28,15 @@ def get_exe_key(exe_name): class SubCommand: __name = None - __parser = None + _parser = None def __init__(self, name, **kwargs): self.__name = name - self.__parser = Parser().get_subparsers().add_parser(name, **kwargs) + self._parser = Parser().get_subparsers().add_parser(name, **kwargs) def __str__(self): return self.__name - def get_parser(self): - return self.__parser - def run(self): pass diff --git a/src/kiwi/subcommands/init.py b/src/kiwi/subcommands/init.py index 530e77a..00b0554 100644 --- a/src/kiwi/subcommands/init.py +++ b/src/kiwi/subcommands/init.py @@ -38,7 +38,7 @@ class InitCommand(SubCommand): description="Create a new kiwi-config instance" ) - self.get_parser().add_argument( + self._parser.add_argument( '-f', '--force', action='store_true', help=f"use default values even if {KIWI_CONF_NAME} is present" diff --git a/src/kiwi/subcommands/logs.py b/src/kiwi/subcommands/logs.py index eea6985..7228cef 100644 --- a/src/kiwi/subcommands/logs.py +++ b/src/kiwi/subcommands/logs.py @@ -1,3 +1,5 @@ +import logging + from ..config import LoadedConfig from ..core import Parser @@ -8,46 +10,55 @@ class LogsCommand(SubCommand): def __init__(self): super().__init__( 'logs', - description="Show logs of a project or service" + description="Show logs of a project or service(s) of a project" ) - self.get_parser().add_argument( + self._parser.add_argument( '-f', '--follow', action='store_true', help="output appended data as log grows" ) - self.get_parser().add_argument( - 'project', - help="narf" + self._parser.add_argument( + 'project', type=str, + help="select a project in this instance" ) - self.get_parser().add_argument( - 'service', nargs='?', - help="narf" + self._parser.add_argument( + 'services', metavar='service', nargs='*', type=str, + help="select service(s) in a project" ) def run(self): config = LoadedConfig.get() + cli_args = Parser().get_args() - project_name = Parser().get_args().project + project_name = cli_args.project project_marker = config['markers:project'] project_dir = f'{project_name}{project_marker}' environment = { - 'KIWI_NET_NAME': config['network:name'], + 'KIWI_HUB_NAME': config['network:name'], 'COMPOSE_PROJECT_NAME': project_name } args = ['logs', '-t'] - if Parser().get_args().follow: + if cli_args.follow: args = [*args, '-f', '--tail=10'] - DockerCommand('docker-compose').run( - args, - cwd=project_dir, env=environment - ) - else: - DockerCommand('docker-compose').run_less( - args, - cwd=project_dir, env=environment - ) + if cli_args.services: + args = [*args, *cli_args.services] + + try: + if cli_args.follow: + DockerCommand('docker-compose').run( + args, + cwd=project_dir, env=environment + ) + else: + DockerCommand('docker-compose').run_less( + args, + cwd=project_dir, env=environment + ) + except KeyboardInterrupt: + logging.debug("Subprocess aborted.") + print()