mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 04:43:00 +00:00
"logs" command finished
This commit is contained in:
parent
0299e6a86f
commit
f94db364d7
5 changed files with 39 additions and 27 deletions
|
@ -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'
|
||||
|
|
1
example/kiwi
Symbolic link
1
example/kiwi
Symbolic link
|
@ -0,0 +1 @@
|
|||
../src/kiwi-config.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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import logging
|
||||
|
||||
from ..config import LoadedConfig
|
||||
from ..core import Parser
|
||||
|
||||
|
@ -8,40 +10,46 @@ 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']
|
||||
|
||||
if cli_args.services:
|
||||
args = [*args, *cli_args.services]
|
||||
|
||||
try:
|
||||
if cli_args.follow:
|
||||
DockerCommand('docker-compose').run(
|
||||
args,
|
||||
cwd=project_dir, env=environment
|
||||
|
@ -51,3 +59,6 @@ class LogsCommand(SubCommand):
|
|||
args,
|
||||
cwd=project_dir, env=environment
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
logging.debug("Subprocess aborted.")
|
||||
print()
|
||||
|
|
Loading…
Reference in a new issue