mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 12:53: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:
|
services:
|
||||||
hello-world:
|
hello-world:
|
||||||
image: alpine:latest
|
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:
|
class SubCommand:
|
||||||
__name = None
|
__name = None
|
||||||
__parser = None
|
_parser = None
|
||||||
|
|
||||||
def __init__(self, name, **kwargs):
|
def __init__(self, name, **kwargs):
|
||||||
self.__name = name
|
self.__name = name
|
||||||
self.__parser = Parser().get_subparsers().add_parser(name, **kwargs)
|
self._parser = Parser().get_subparsers().add_parser(name, **kwargs)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.__name
|
return self.__name
|
||||||
|
|
||||||
def get_parser(self):
|
|
||||||
return self.__parser
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class InitCommand(SubCommand):
|
||||||
description="Create a new kiwi-config instance"
|
description="Create a new kiwi-config instance"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.get_parser().add_argument(
|
self._parser.add_argument(
|
||||||
'-f', '--force',
|
'-f', '--force',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help=f"use default values even if {KIWI_CONF_NAME} is present"
|
help=f"use default values even if {KIWI_CONF_NAME} is present"
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from ..config import LoadedConfig
|
from ..config import LoadedConfig
|
||||||
from ..core import Parser
|
from ..core import Parser
|
||||||
|
|
||||||
|
@ -8,40 +10,46 @@ class LogsCommand(SubCommand):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
'logs',
|
'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',
|
'-f', '--follow', action='store_true',
|
||||||
help="output appended data as log grows"
|
help="output appended data as log grows"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.get_parser().add_argument(
|
self._parser.add_argument(
|
||||||
'project',
|
'project', type=str,
|
||||||
help="narf"
|
help="select a project in this instance"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.get_parser().add_argument(
|
self._parser.add_argument(
|
||||||
'service', nargs='?',
|
'services', metavar='service', nargs='*', type=str,
|
||||||
help="narf"
|
help="select service(s) in a project"
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
config = LoadedConfig.get()
|
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_marker = config['markers:project']
|
||||||
project_dir = f'{project_name}{project_marker}'
|
project_dir = f'{project_name}{project_marker}'
|
||||||
|
|
||||||
environment = {
|
environment = {
|
||||||
'KIWI_NET_NAME': config['network:name'],
|
'KIWI_HUB_NAME': config['network:name'],
|
||||||
'COMPOSE_PROJECT_NAME': project_name
|
'COMPOSE_PROJECT_NAME': project_name
|
||||||
}
|
}
|
||||||
|
|
||||||
args = ['logs', '-t']
|
args = ['logs', '-t']
|
||||||
if Parser().get_args().follow:
|
if cli_args.follow:
|
||||||
args = [*args, '-f', '--tail=10']
|
args = [*args, '-f', '--tail=10']
|
||||||
|
|
||||||
|
if cli_args.services:
|
||||||
|
args = [*args, *cli_args.services]
|
||||||
|
|
||||||
|
try:
|
||||||
|
if cli_args.follow:
|
||||||
DockerCommand('docker-compose').run(
|
DockerCommand('docker-compose').run(
|
||||||
args,
|
args,
|
||||||
cwd=project_dir, env=environment
|
cwd=project_dir, env=environment
|
||||||
|
@ -51,3 +59,6 @@ class LogsCommand(SubCommand):
|
||||||
args,
|
args,
|
||||||
cwd=project_dir, env=environment
|
cwd=project_dir, env=environment
|
||||||
)
|
)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logging.debug("Subprocess aborted.")
|
||||||
|
print()
|
||||||
|
|
Loading…
Reference in a new issue