2021-10-20 06:31:36 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
import click
|
|
|
|
|
2021-10-29 11:37:59 +00:00
|
|
|
from ..instance import Instance
|
|
|
|
|
2021-10-20 06:31:36 +00:00
|
|
|
|
|
|
|
class KiwiCLI(click.MultiCommand):
|
2021-10-20 08:54:41 +00:00
|
|
|
"""Command Line Interface spread over multiple files in this directory"""
|
|
|
|
|
2021-10-20 06:31:36 +00:00
|
|
|
def list_commands(self, ctx):
|
2021-10-20 08:54:41 +00:00
|
|
|
"""list all the commands defined by cmd_*.py files in this directory"""
|
|
|
|
|
|
|
|
return (
|
|
|
|
filename[4:-3]
|
|
|
|
for filename in os.listdir(os.path.abspath(os.path.dirname(__file__)))
|
|
|
|
if filename.startswith("cmd_") and filename.endswith(".py")
|
|
|
|
)
|
2021-10-20 06:31:36 +00:00
|
|
|
|
|
|
|
def get_command(self, ctx, name):
|
2021-10-20 08:54:41 +00:00
|
|
|
"""import and return a specific command"""
|
|
|
|
|
2021-10-20 06:31:36 +00:00
|
|
|
try:
|
|
|
|
mod = __import__(f"kiwi_scp.commands.cmd_{name}", None, None, ["cmd"])
|
|
|
|
except ImportError:
|
|
|
|
return
|
|
|
|
return mod.cmd
|
2021-10-29 11:37:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
pass_instance = click.make_pass_decorator(Instance, ensure=True)
|