clan-cli: Fix incorrect input handling in get_templates

This commit is contained in:
Qubasa
2025-02-04 14:28:56 +07:00
committed by clan-bot
parent da0f792d9e
commit bf26a2d306
3 changed files with 13 additions and 3 deletions

View File

@@ -113,9 +113,10 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
type=str, type=str,
help="""Flake input name to use as template source help="""Flake input name to use as template source
can be specified multiple times, inputs are tried in order of definition can be specified multiple times, inputs are tried in order of definition
Example: --input clan --input clan-core
""", """,
action="append", action="append",
default=["clan-core"], default=[],
) )
parser.add_argument( parser.add_argument(
@@ -147,6 +148,9 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
) )
def create_flake_command(args: argparse.Namespace) -> None: def create_flake_command(args: argparse.Namespace) -> None:
if len(args.input) == 0:
args.input = ["clan", "clan-core"]
if args.no_self: if args.no_self:
input_prio = InputPrio.try_inputs(tuple(args.input)) input_prio = InputPrio.try_inputs(tuple(args.input))
else: else:

View File

@@ -136,6 +136,9 @@ def create_command(args: argparse.Namespace) -> None:
) )
raise ClanError(msg, description=description) raise ClanError(msg, description=description)
if len(args.input) == 0:
args.input = ["clan", "clan-core"]
if args.no_self: if args.no_self:
input_prio = InputPrio.try_inputs(tuple(args.input)) input_prio = InputPrio.try_inputs(tuple(args.input))
else: else:
@@ -185,9 +188,10 @@ def register_create_parser(parser: argparse.ArgumentParser) -> None:
type=str, type=str,
help="""Flake input name to use as template source help="""Flake input name to use as template source
can be specified multiple times, inputs are tried in order of definition can be specified multiple times, inputs are tried in order of definition
Example: --input clan --input clan-core
""", """,
action="append", action="append",
default=["clan-core"], default=[],
) )
parser.add_argument( parser.add_argument(
"--no-self", "--no-self",

View File

@@ -237,7 +237,9 @@ def get_template(
input_name = InputName(input_name_str) input_name = InputName(input_name_str)
log.debug(f"Checking input '{input_name}' for template '{template_name}'") log.debug(f"Checking input '{input_name}' for template '{template_name}'")
template = find_template(template_name, template_list.inputs[input_name]) template = find_template(
template_name, template_list.inputs.get(input_name, {})
)
if template: if template:
log.debug(f"Found template '{template_name}' in input '{input_name}'") log.debug(f"Found template '{template_name}' in input '{input_name}'")
break # Stop searching once the template is found break # Stop searching once the template is found