Add ability to run subset of menus

This commit is contained in:
Olivier 'reivilibre' 2020-11-09 12:01:14 +00:00
parent 55e75f3faf
commit d9b0eabd8d
2 changed files with 20 additions and 5 deletions

View File

@ -45,6 +45,13 @@ async def cli_async() -> int:
parser = ArgumentParser(description="Cook!")
parser.add_argument("hostspec", type=str, help="Sous or group name")
parser.add_argument(
"--menu",
"-m",
type=str,
help="Specify a comma-separated list of names of menu to cook. "
"If not specified, all menus will be cooked.",
)
parser.add_argument(
"--yes",
"-y",
@ -64,7 +71,11 @@ async def cli_async() -> int:
eprint("Don't appear to be in a head. STOP.")
return 1
head = Head.open(str(cdir))
menu_subset = None
if argp.menu:
menu_subset = argp.menu.split(",")
head = Head.open(str(cdir), menu_subset)
eprint(head.debug_info())

View File

@ -58,7 +58,7 @@ class Head:
self.pools = pools
@staticmethod
def open(directory: str):
def open(directory: str, menu_subset: Optional[List[str]] = None):
with open(path.join(directory, "scone.head.toml")) as head_toml:
head_data = toml.load(head_toml)
@ -85,7 +85,7 @@ class Head:
head = Head(directory, recipe_loader, sous, groups, secret_access, pools)
head._load_variables()
head._load_menus()
head._load_menus(menu_subset)
return head
def _preload_variables(self, who_for: str) -> Tuple[dict, dict]:
@ -159,9 +159,13 @@ class Head:
self.variables[sous_name] = sous_vars
def _load_menus(self):
def _load_menus(self, subset: Optional[List[str]]):
loader = MenuLoader(Path(self.directory, "menu"), self)
loader.load_menus_in_dir()
if subset:
for unit in subset:
loader.load(unit)
else:
loader.load_menus_in_dir()
loader.dagify_all()
# TODO remove