mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 12:53:00 +00:00
nargs for ProjectCommand and ServiceCommand
This commit is contained in:
parent
8adbb5b2a0
commit
1cf3b5ca55
5 changed files with 19 additions and 14 deletions
|
@ -28,33 +28,38 @@ class SubCommand:
|
||||||
class ProjectCommand(SubCommand):
|
class ProjectCommand(SubCommand):
|
||||||
"""this command concerns a project in current instance"""
|
"""this command concerns a project in current instance"""
|
||||||
|
|
||||||
def __init__(self, name, **kwargs):
|
def __init__(self, name, num_projects, **kwargs):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
name,
|
name,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
projects = "a project"
|
||||||
|
|
||||||
|
if not str(num_projects) == '1':
|
||||||
|
projects = "projects"
|
||||||
|
|
||||||
self._sub_parser.add_argument(
|
self._sub_parser.add_argument(
|
||||||
'project', type=str,
|
'projects', metavar='project', nargs=num_projects, type=str,
|
||||||
help="select a project in this instance"
|
help=f"select {projects} in this instance"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ServiceCommand(ProjectCommand):
|
class ServiceCommand(ProjectCommand):
|
||||||
"""this command concerns service(s) in a project"""
|
"""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__(
|
super().__init__(
|
||||||
name,
|
name, num_projects=num_projects,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
services = "service"
|
services = "a service"
|
||||||
|
|
||||||
if not nargs == 1:
|
if not str(num_services) == '1':
|
||||||
services = "services"
|
services = "services"
|
||||||
|
|
||||||
self._sub_parser.add_argument(
|
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"
|
help=f"select {services} in a project"
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,7 +8,7 @@ class CmdCommand(ProjectCommand):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
'cmd',
|
'cmd', num_projects=1,
|
||||||
description="Run raw docker-compose command in a project"
|
description="Run raw docker-compose command in a project"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ class LogsCommand(ServiceCommand):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
'logs', nargs='*',
|
'logs', num_projects=1, num_services='*',
|
||||||
description="Show logs of a project or service(s) of a project"
|
description="Show logs of a project or service(s) of a project"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -72,11 +72,11 @@ class ShCommand(ServiceCommand):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
'sh',
|
'sh', num_projects=1, num_services=1,
|
||||||
description="Spawn shell inside a project's service"
|
description="Spawn shell inside a project's service"
|
||||||
)
|
)
|
||||||
|
|
||||||
# -s switch: Select shell
|
# -s argument: Select shell
|
||||||
self._sub_parser.add_argument(
|
self._sub_parser.add_argument(
|
||||||
'-s', '--shell', type=str,
|
'-s', '--shell', type=str,
|
||||||
help="shell to spawn"
|
help="shell to spawn"
|
||||||
|
|
|
@ -8,10 +8,10 @@ from .executable import Executable
|
||||||
|
|
||||||
|
|
||||||
def _update_kwargs(config, args, **kwargs):
|
def _update_kwargs(config, args, **kwargs):
|
||||||
if 'project' in args:
|
if 'projects' in args:
|
||||||
# command affects a project in this instance
|
# command affects a project in this instance
|
||||||
|
|
||||||
project_name = args.project
|
project_name = args.projects[0]
|
||||||
project_marker = config['markers:project']
|
project_marker = config['markers:project']
|
||||||
project_dir = f'{project_name}{project_marker}'
|
project_dir = f'{project_name}{project_marker}'
|
||||||
kwargs['cwd'] = project_dir
|
kwargs['cwd'] = project_dir
|
||||||
|
|
Loading…
Reference in a new issue