From 79ec42a655ec0a2be318a2244d7880af5dad8460 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 28 Mar 2017 09:04:02 +0100 Subject: [PATCH] Create base CLI and read input files --- md_pdf/build/cli.py | 8 ++++++-- md_pdf/build/md.py | 3 +-- md_pdf/cli.py | 5 +++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/md_pdf/build/cli.py b/md_pdf/build/cli.py index 4c68dd7..0eb2ee2 100644 --- a/md_pdf/build/cli.py +++ b/md_pdf/build/cli.py @@ -1,5 +1,9 @@ import click +from md_pdf.build.md import read_files @click.command('build', short_help="Build document") -def cli(): - pass +@click.argument('in_files', type=click.Path(dir_okay=False, resolve_path=True, writable=True), nargs=-1) +@click.option('--output', '-o', type=click.Path(file_okay=False, resolve_path=True, writable=True), default='out/') +def cli(in_files, output): + data = read_files(in_files) + print(data) diff --git a/md_pdf/build/md.py b/md_pdf/build/md.py index 07188ad..fb92365 100644 --- a/md_pdf/build/md.py +++ b/md_pdf/build/md.py @@ -6,6 +6,5 @@ def get_files_content(filenames): yield f.read() -def read_files(files_glob): - filenames = glob.glob(files_glob) +def read_files(filenames): return '\n'.join(list(get_files_content(filenames))) diff --git a/md_pdf/cli.py b/md_pdf/cli.py index 361593e..facb294 100644 --- a/md_pdf/cli.py +++ b/md_pdf/cli.py @@ -23,8 +23,9 @@ class MDPDFCLI(click.MultiCommand): code = compile(f.read(), fn, 'exec') eval(code, ns, ns) return ns['cli'] - except: - return + except Exception as e: + print("An Error Occured:s") + raise e cli = MDPDFCLI(help='This tool\'s subcommands are loaded from a plugin folder dynamically.')