1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 04:43:00 +00:00

nargs for ProjectCommand and ServiceCommand

This commit is contained in:
Jörn-Michael Miehe 2020-08-17 12:58:18 +02:00
parent 8adbb5b2a0
commit 1cf3b5ca55
5 changed files with 19 additions and 14 deletions

View file

@ -28,33 +28,38 @@ class SubCommand:
class ProjectCommand(SubCommand):
"""this command concerns a project in current instance"""
def __init__(self, name, **kwargs):
def __init__(self, name, num_projects, **kwargs):
super().__init__(
name,
**kwargs
)
projects = "a project"
if not str(num_projects) == '1':
projects = "projects"
self._sub_parser.add_argument(
'project', type=str,
help="select a project in this instance"
'projects', metavar='project', nargs=num_projects, type=str,
help=f"select {projects} in this instance"
)
class ServiceCommand(ProjectCommand):
"""this command concerns service(s) in a project"""
def __init__(self, name, nargs=1, **kwargs):
def __init__(self, name, num_projects, num_services, **kwargs):
super().__init__(
name,
name, num_projects=num_projects,
**kwargs
)
services = "service"
services = "a service"
if not nargs == 1:
if not str(num_services) == '1':
services = "services"
self._sub_parser.add_argument(
'services', metavar='service', nargs=nargs, type=str,
'services', metavar='service', nargs=num_services, type=str,
help=f"select {services} in a project"
)

View file

@ -8,7 +8,7 @@ class CmdCommand(ProjectCommand):
def __init__(self):
super().__init__(
'cmd',
'cmd', num_projects=1,
description="Run raw docker-compose command in a project"
)

View file

@ -8,7 +8,7 @@ class LogsCommand(ServiceCommand):
def __init__(self):
super().__init__(
'logs', nargs='*',
'logs', num_projects=1, num_services='*',
description="Show logs of a project or service(s) of a project"
)

View file

@ -72,11 +72,11 @@ class ShCommand(ServiceCommand):
def __init__(self):
super().__init__(
'sh',
'sh', num_projects=1, num_services=1,
description="Spawn shell inside a project's service"
)
# -s switch: Select shell
# -s argument: Select shell
self._sub_parser.add_argument(
'-s', '--shell', type=str,
help="shell to spawn"

View file

@ -8,10 +8,10 @@ from .executable import Executable
def _update_kwargs(config, args, **kwargs):
if 'project' in args:
if 'projects' in args:
# command affects a project in this instance
project_name = args.project
project_name = args.projects[0]
project_marker = config['markers:project']
project_dir = f'{project_name}{project_marker}'
kwargs['cwd'] = project_dir