with an example option

This commit is contained in:
Jörn-Michael Miehe 2021-10-29 13:59:57 +02:00
parent ff256d05d3
commit 57a9a50c90

View file

@ -37,43 +37,50 @@ def kiwi_command(
print(f"{ctx.directory!r}: {project!r}, {services!r}") print(f"{ctx.directory!r}: {project!r}, {services!r}")
if project is None: if project is None:
# run for whole instance # run for whole instance
print("instance") print(f"for instance: {cmd_kwargs}")
command_cls.run_for_instance(ctx, **cmd_kwargs) command_cls.run_for_instance(ctx, **cmd_kwargs)
elif not services: elif not services:
# run for one entire project # run for one entire project
print("project") print(f"for project {project}: {cmd_kwargs}")
for project_cfg in ctx.config.projects: for project_cfg in ctx.config.projects:
if project_cfg.name == project: if project_cfg.name == project:
command_cls.run_for_project(ctx, project_cfg, **kwargs) command_cls.run_for_project(ctx, project_cfg, **cmd_kwargs)
else: else:
# run for some services # run for some services
print("services") print(f"for services {project}.{services}: {cmd_kwargs}")
for project_cfg in ctx.config.projects: for project_cfg in ctx.config.projects:
if project_cfg.name == project: if project_cfg.name == project:
services = ctx.get_services(project_cfg.name, services) services = ctx.get_services(project_cfg.name, services)
command_cls.run_for_services(ctx, project_cfg, services) command_cls.run_for_services(ctx, project_cfg, services, **cmd_kwargs)
return cmd return cmd
return decorator return decorator
@click.option(
"-s/-S",
"--show/--no-show",
help=f"EXAMPLE",
)
@kiwi_command( @kiwi_command(
"list", "list",
short_help="Inspect a kiwi-scp instance", short_help="Inspect a kiwi-scp instance",
) )
class cmd(KiwiCommand): class cmd(KiwiCommand):
@classmethod @classmethod
def run_for_instance(cls, instance: Instance, **kwargs): def run_for_instance(cls, instance: Instance, show: bool = None, **kwargs):
print(show)
print(instance.config.projects) print(instance.config.projects)
@classmethod @classmethod
def run_for_services(cls, instance: Instance, project: ProjectConfig, services: Services, **kwargs): def run_for_services(cls, instance: Instance, project: ProjectConfig, services: Services, show: bool = None,
**kwargs):
print(show)
print(services) print(services)
# @click.command( # @click.command(
# "list", # "list",
# short_help="Inspect a kiwi-scp instance", # short_help="Inspect a kiwi-scp instance",