This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
md-pdf/md_pdf/cli.py

41 lines
930 B
Python
Raw Normal View History

2017-03-27 09:02:05 +01:00
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 MDPDFCLI(click.MultiCommand):
def list_commands(self, ctx):
return ['build']
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']
2017-03-28 09:04:02 +01:00
except Exception as e:
print("An Error Occured:s")
raise e
2017-03-27 09:02:05 +01:00
cli = MDPDFCLI(help='This tool\'s subcommands are loaded from a plugin folder dynamically.')
@click.command(cls=MDPDFCLI)
def cli():
pass
if __name__ == '__main__':
cli()