diff --git a/src/kiwi/subcommands/_subcommand.py b/src/kiwi/subcommands/_subcommand.py index 59b04f8..e7c0274 100644 --- a/src/kiwi/subcommands/_subcommand.py +++ b/src/kiwi/subcommands/_subcommand.py @@ -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" ) diff --git a/src/kiwi/subcommands/cmd.py b/src/kiwi/subcommands/cmd.py index 4aba79c..a935880 100644 --- a/src/kiwi/subcommands/cmd.py +++ b/src/kiwi/subcommands/cmd.py @@ -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" ) diff --git a/src/kiwi/subcommands/logs.py b/src/kiwi/subcommands/logs.py index 178713e..5a22912 100644 --- a/src/kiwi/subcommands/logs.py +++ b/src/kiwi/subcommands/logs.py @@ -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" ) diff --git a/src/kiwi/subcommands/sh.py b/src/kiwi/subcommands/sh.py index 9c2b1df..17d5ca8 100644 --- a/src/kiwi/subcommands/sh.py +++ b/src/kiwi/subcommands/sh.py @@ -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" diff --git a/src/kiwi/subcommands/utils/dockercommand.py b/src/kiwi/subcommands/utils/dockercommand.py index 1fd06e0..1fca7b6 100644 --- a/src/kiwi/subcommands/utils/dockercommand.py +++ b/src/kiwi/subcommands/utils/dockercommand.py @@ -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