|
17 | 17 | # License along with C-PAC. If not, see <https://www.gnu.org/licenses/>. |
18 | 18 | """Inspect inputs and outputs for NodeBlockFunctions.""" |
19 | 19 |
|
| 20 | +from argparse import ArgumentParser, Namespace |
20 | 21 | import ast |
21 | 22 | from dataclasses import dataclass, field |
22 | 23 | import importlib |
23 | 24 | from importlib.resources import files |
24 | 25 | import inspect |
25 | 26 | from itertools import chain |
26 | 27 | import os |
| 28 | +from pathlib import Path |
27 | 29 | from typing import Any, cast, Iterable |
28 | 30 |
|
29 | 31 | import yaml |
@@ -181,6 +183,22 @@ def as_dict(self) -> dict[str, list[str]]: |
181 | 183 | } |
182 | 184 |
|
183 | 185 |
|
| 186 | +def cli_parser() -> Namespace: |
| 187 | + """Parse command line argument.""" |
| 188 | + parser = ArgumentParser( |
| 189 | + description="Inventory resources for C-PAC NodeBlockFunctions." |
| 190 | + ) |
| 191 | + parser.add_argument( |
| 192 | + "-o", |
| 193 | + "--output", |
| 194 | + nargs="?", |
| 195 | + help="The output file to write the inventory to.", |
| 196 | + type=Path, |
| 197 | + default=Path("resource_inventory.yaml"), |
| 198 | + ) |
| 199 | + return parser.parse_args() |
| 200 | + |
| 201 | + |
184 | 202 | def _flatten_io(io: list[Iterable]) -> list[str]: |
185 | 203 | """Given a list of strings or iterables thereof, flatten the list to all strings.""" |
186 | 204 | if all(isinstance(resource, str) for resource in io): |
@@ -292,8 +310,10 @@ def dump_inventory_to_yaml(inventory: dict[str, ResourceIO]) -> str: |
292 | 310 |
|
293 | 311 |
|
294 | 312 | def main() -> None: |
295 | | - """Print the NodeBlock IO to the console.""" |
296 | | - UTLOGGER.info(dump_inventory_to_yaml(resource_inventory("CPAC"))) # noqa: T201 |
| 313 | + """Save the NodeBlock inventory to a file.""" |
| 314 | + args = cli_parser() |
| 315 | + with args.output.open("w") as file: |
| 316 | + file.write(dump_inventory_to_yaml(resource_inventory("CPAC"))) |
297 | 317 |
|
298 | 318 |
|
299 | 319 | if __name__ == "__main__": |
|
0 commit comments