From 2f50f51763b121b5f412f4c9ea25a7ecdb628517 Mon Sep 17 00:00:00 2001 From: Manolis Stamatogiannakis Date: Sun, 8 Aug 2021 23:18:15 +0300 Subject: [PATCH] dep --- src/jj2cli/cli.py | 25 ++++++++++++++++++++++++- src/jj2cli/defaults.py | 5 +++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/jj2cli/cli.py b/src/jj2cli/cli.py index 0b0ff97..1965b02 100644 --- a/src/jj2cli/cli.py +++ b/src/jj2cli/cli.py @@ -12,7 +12,7 @@ from . import __version__, filters, parsers from .customize import CustomizationModule -from .defaults import CONTEXT_FORMATS +from .defaults import CONTEXT_FORMATS, DEPENDENCIES_OUTPUT_FORMATS from .render import Jinja2TemplateRenderer # available log levels, adjusted with -v at command line @@ -138,4 +138,27 @@ def render(): def dependencies(): """ CLI entry point for analyzing template dependencies. """ + #version_info = (__version__, jinja2.__version__) + parser = argparse.ArgumentParser( + description='Analyze Jinja2 templates for dependencies.', + epilog='', + formatter_class=argparse.ArgumentDefaultsHelpFormatter + ) + p_input = parser.add_argument_group('input options') + p_output = parser.add_argument_group('output options') + p_output_mode = p_output.add_mutually_exclusive_group() + ### input options ############################################### + p_input.add_argument('templates', metavar='TEMPLATE', nargs='+', + type=argparse.FileType('r', encoding='utf-8')) + ### output options ############################################## + p_output.add_argument('-f', '--format', + default='make', choices=sorted(DEPENDENCIES_OUTPUT_FORMATS), + help='Specify output format for dependencies.') + p_output_mode.add_argument('-o', metavar='outfile', dest='output_file', + help="Output to a file instead of stdout.") + p_output_mode.add_argument('--per-file', action='store_true', dest='per_file', + help='Produce one output file per input file.') + + args = parser.parse_args() + print(args) raise NotImplementedError("jj2dep has not yet been implemented.") diff --git a/src/jj2cli/defaults.py b/src/jj2cli/defaults.py index 8b62d11..69ec48b 100644 --- a/src/jj2cli/defaults.py +++ b/src/jj2cli/defaults.py @@ -33,3 +33,8 @@ # Variables for parsing dataspecs. DATASPEC_SEP = ':' DATASPEC_COMPONENTS_MAX = 3 + +# Supported formats for outputting template dependencies. +DEPENDENCIES_OUTPUT_FORMATS = ['make', 'json', 'yaml', 'delim'] +if yaml_load is None: + DEPENDENCIES_OUTPUT_FORMATS.remove('yaml')