Add support for multiple prepended files

This commit is contained in:
Daniel Rojas 2021-10-16 16:59:28 +02:00 committed by Laurier Loiselle
parent c1f195fe86
commit 8796709195
No known key found for this signature in database
GPG Key ID: 345920CC72089A3F
2 changed files with 16 additions and 13 deletions

View File

@ -3,7 +3,7 @@
import sys import sys
from pathlib import Path from pathlib import Path
from typing import Any, Dict, List, Union, Tuple from typing import Any, Dict, List, Tuple, Union
import yaml import yaml

View File

@ -41,7 +41,8 @@ epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.i
@click.option( @click.option(
"-p", "-p",
"--prepend", "--prepend",
default=None, default=[],
multiple=True,
type=Path, type=Path,
help="YAML file to prepend to the input file (optional).", help="YAML file to prepend to the input file (optional).",
) )
@ -97,20 +98,19 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
else output_formats[0] else output_formats[0]
) )
image_paths = []
# check prepend file # check prepend file
if prepend: if len(prepend) > 0:
prepend = Path(prepend) prepend_input = ""
if not prepend.exists(): for prepend_file in prepend:
raise Exception(f"File does not exist:\n{prepend}") prepend_file = Path(prepend_file)
print("Prepend file:", prepend) if not prepend_file.exists():
raise Exception(f"File does not exist:\n{prepend_file}")
print("Prepend file:", prepend_file)
with open_file_read(prepend) as file_handle: with open_file_read(prepend_file) as file_handle:
prepend_input = file_handle.read() + "\n" prepend_input += file_handle.read() + "\n"
prepend_dir = prepend.parent
else: else:
prepend_input = "" prepend_input = ""
prepend_dir = None
# run WireVIz on each input file # run WireVIz on each input file
for file in filepaths: for file in filepaths:
@ -132,13 +132,16 @@ def wireviz(file, format, prepend, output_dir, output_name, version):
file_dir = file.parent file_dir = file.parent
yaml_input = prepend_input + yaml_input yaml_input = prepend_input + yaml_input
image_paths = {file_dir}
for p in prepend:
image_paths.add(Path(p).parent)
wv.parse( wv.parse(
yaml_input, yaml_input,
output_formats=output_formats, output_formats=output_formats,
output_dir=_output_dir, output_dir=_output_dir,
output_name=_output_name, output_name=_output_name,
image_paths=[file_dir, prepend_dir], image_paths=list(image_paths),
) )
print() print()