From 08b5124adb8b2d398fd2e1146adf865291c91a52 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sat, 16 Oct 2021 16:59:28 +0200 Subject: [PATCH] Add support for multiple prepended files --- src/wireviz/wireviz.py | 2 +- src/wireviz/wv_cli.py | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index 329b3d2f..e82fbfea 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -3,7 +3,7 @@ import sys from pathlib import Path -from typing import Any, Dict, List, Union, Tuple +from typing import Any, Dict, List, Tuple, Union import yaml diff --git a/src/wireviz/wv_cli.py b/src/wireviz/wv_cli.py index 6632b90e..83ff164b 100644 --- a/src/wireviz/wv_cli.py +++ b/src/wireviz/wv_cli.py @@ -41,7 +41,8 @@ @click.option( "-p", "--prepend", - default=None, + default=[], + multiple=True, type=Path, 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] ) - image_paths = [] # check prepend file - if prepend: - prepend = Path(prepend) - if not prepend.exists(): - raise Exception(f"File does not exist:\n{prepend}") - print("Prepend file:", prepend) - - with open_file_read(prepend) as file_handle: - prepend_input = file_handle.read() + "\n" - prepend_dir = prepend.parent + if len(prepend) > 0: + prepend_input = "" + for prepend_file in prepend: + prepend_file = Path(prepend_file) + 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_file) as file_handle: + prepend_input += file_handle.read() + "\n" else: prepend_input = "" - prepend_dir = None # run WireVIz on each input file for file in filepaths: @@ -132,13 +132,16 @@ def wireviz(file, format, prepend, output_dir, output_name, version): file_dir = file.parent yaml_input = prepend_input + yaml_input + image_paths = {file_dir} + for p in prepend: + image_paths.add(Path(p).parent) wv.parse( yaml_input, output_formats=output_formats, output_dir=_output_dir, output_name=_output_name, - image_paths=[file_dir, prepend_dir], + image_paths=list(image_paths), ) print()