Skip to content

Commit 236e0fe

Browse files
committed
🚸 Add CLI for resource inventory
1 parent 5758eed commit 236e0fe

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

CPAC/pipeline/resource_inventory.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
1818
"""Inspect inputs and outputs for NodeBlockFunctions."""
1919

20+
from argparse import ArgumentParser, Namespace
2021
import ast
2122
from dataclasses import dataclass, field
2223
import importlib
2324
from importlib.resources import files
2425
import inspect
2526
from itertools import chain
2627
import os
28+
from pathlib import Path
2729
from typing import Any, cast, Iterable
2830

2931
import yaml
@@ -181,6 +183,22 @@ def as_dict(self) -> dict[str, list[str]]:
181183
}
182184

183185

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+
184202
def _flatten_io(io: list[Iterable]) -> list[str]:
185203
"""Given a list of strings or iterables thereof, flatten the list to all strings."""
186204
if all(isinstance(resource, str) for resource in io):
@@ -292,8 +310,10 @@ def dump_inventory_to_yaml(inventory: dict[str, ResourceIO]) -> str:
292310

293311

294312
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")))
297317

298318

299319
if __name__ == "__main__":

0 commit comments

Comments
 (0)