1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 21:03:00 +00:00
kiwi-scp/kiwi_scp/commands/cli.py

31 lines
821 B
Python
Raw Normal View History

import os
import click
2021-10-29 11:37:59 +00:00
from ..instance import Instance
class KiwiCLI(click.MultiCommand):
"""Command Line Interface spread over multiple files in this directory"""
def list_commands(self, ctx):
"""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")
)
def get_command(self, ctx, name):
"""import and return a specific command"""
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)