1
Fork 0

Added project core CLI

This commit is contained in:
Jake Howard 2015-11-27 18:14:35 +00:00
parent 2fb871bfbe
commit e24aea7745
2 changed files with 37 additions and 0 deletions

37
project/cli.py Normal file
View File

@ -0,0 +1,37 @@
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 DotFileCLI(click.MultiCommand):
def list_commands(self, ctx):
return []
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 = DotFileCLI(help='This tool\'s subcommands are loaded from a plugin folder dynamically.')
if __name__ == '__main__':
cli()
@click.command(cls=DotFileCLI)
def cli():
pass

0
scripts/__init__.py Normal file
View File