From 2e9e58d8f4eb7ea3b5e0175e193c7dace0634500 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 18 May 2016 22:10:19 +0100 Subject: [PATCH] Add base CLI --- yubi_lock/__init__.py | 0 yubi_lock/cli.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 yubi_lock/__init__.py create mode 100644 yubi_lock/cli.py diff --git a/yubi_lock/__init__.py b/yubi_lock/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/yubi_lock/cli.py b/yubi_lock/cli.py new file mode 100644 index 0000000..cc879b4 --- /dev/null +++ b/yubi_lock/cli.py @@ -0,0 +1,32 @@ +import os.path +import click +import logging + + +FORMAT = "[%(levelname)s]: %(message)s" +logging.basicConfig(format=FORMAT, level=logging.DEBUG) +logging.getLogger("requests").setLevel(logging.WARNING) + + +class YubiLockCLI(click.MultiCommand): + + def list_commands(self, ctx): + return ['status'] + + def get_command(self, ctx, name): + ns = {} + if name not in self.list_commands(ctx): + return + try: + fn = os.path.join(os.path.dirname(__file__), name + '/cli.py') + with open(fn) as f: + code = compile(f.read(), fn, 'exec') + eval(code, ns, ns) + return ns['cli'] + except: + return + +cli = YubiLockCLI(help='This tool\'s subcommands are loaded from a plugin folder dynamically.') + +if __name__ == '__main__': + cli()