1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 12:53:00 +00:00
kiwi-scp/src/kiwi/subcommands/_subcommand.py

66 lines
1.6 KiB
Python
Raw Normal View History

2020-08-12 15:46:50 +00:00
# parent
2020-08-12 14:43:13 +00:00
from ..parser import Parser
class SubCommand:
2020-08-13 08:48:01 +00:00
"""represents kiwi [anything] command"""
# actual command string
2020-08-12 14:43:13 +00:00
__name = None
2020-08-13 08:48:01 +00:00
# command parser
2020-08-12 14:43:13 +00:00
_sub_parser = None
def __init__(self, name, **kwargs):
self.__name = name
2020-08-13 08:48:01 +00:00
self._sub_parser = Parser().get_subparsers().add_parser(
name,
**kwargs
)
2020-08-12 14:43:13 +00:00
def __str__(self):
return self.__name
2020-08-17 08:57:45 +00:00
def run(self, runner, config, args):
2020-08-13 08:48:01 +00:00
"""actually run command with this dir's config and parsed CLI args"""
2020-08-12 14:43:13 +00:00
pass
class ProjectCommand(SubCommand):
"""this command concerns a project in current instance"""
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(
'projects', metavar='project', nargs=num_projects, type=str,
help=f"select {projects} in this instance"
)
class ServiceCommand(ProjectCommand):
2020-08-13 12:26:49 +00:00
"""this command concerns service(s) in a project"""
def __init__(self, name, num_projects, num_services, **kwargs):
super().__init__(
name, num_projects=num_projects,
**kwargs
)
services = "a service"
2020-08-13 12:26:49 +00:00
if not str(num_services) == '1':
2020-08-13 12:26:49 +00:00
services = "services"
self._sub_parser.add_argument(
'services', metavar='service', nargs=num_services, type=str,
2020-08-13 12:26:49 +00:00
help=f"select {services} in a project"
)