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
|
2020-08-08 17:41:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LogsCommand(SubCommand):
|
2020-08-10 13:48:15 +00:00
|
|
|
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-08 17:41:11 +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"
|
|
|
|
)
|
|
|
|
|
2020-08-10 13:48:15 +00:00
|
|
|
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 = {
|
2020-08-11 09:20:08 +00:00
|
|
|
'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
|
|
|
|
)
|