kiwi-scp/src/kiwi/subcommands/logs.py

54 lines
1.4 KiB
Python
Raw Normal View History

2020-08-10 15:40:56 +00:00
from ..config import LoadedConfig
2020-08-10 14:36:05 +00:00
from ..core import Parser
2020-08-10 15:40:56 +00:00
from ._utils import SubCommand, DockerCommand
class LogsCommand(SubCommand):
def __init__(self):
super().__init__(
'logs',
2020-08-10 14:36:05 +00:00
description="Show logs of a project or service"
)
self.get_parser().add_argument(
2020-08-10 15:40:56 +00:00
'-f', '--follow', action='store_true',
2020-08-10 14:36:05 +00:00
help="output appended data as log grows"
2020-08-10 09:24:39 +00:00
)
2020-08-10 15:40:56 +00:00
self.get_parser().add_argument(
'project',
help="narf"
)
self.get_parser().add_argument(
'service', nargs='?',
help="narf"
)
def run(self):
2020-08-10 15:40:56 +00:00
config = LoadedConfig.get()
project_name = Parser().get_args().project
project_marker = config['markers:project']
project_dir = f'{project_name}{project_marker}'
environment = {
'KIWI_NET_NAME': config['network:name'],
2020-08-10 15:40:56 +00:00
'COMPOSE_PROJECT_NAME': project_name
}
2020-08-10 14:36:05 +00:00
args = ['logs', '-t']
if Parser().get_args().follow:
args = [*args, '-f', '--tail=10']
2020-08-10 15:40:56 +00:00
DockerCommand('docker-compose').run(
args,
cwd=project_dir, env=environment
)
else:
DockerCommand('docker-compose').run_less(
args,
cwd=project_dir, env=environment
)