jw-pkg secrets compile-templates iterates over all selected templates and compiles secrets from it - unless it encounters one that can't be compiled for whatever reason, in which case the iteration errors out without compiling the remaining secrets. Add a -k / --keep-going option that makes the iteration not abort over failed compilations but continue through the remaining templates, then report an error status at the end. The integration test gains a good sibling of the failing fixture template: a fail-fast run must not reach it, and a keep-going run must compile it and still fail the command. Signed-off-by: Jan Lindemann <jan@janware.com> Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.4.0
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from argparse import ArgumentParser, ArgumentTypeError, Namespace
|
|
from typing import override
|
|
|
|
from .Cmd import Cmd, Parent
|
|
from .lib.base import Attrs
|
|
|
|
def octal_mode(s: str) -> int:
|
|
try:
|
|
return int(s, 8)
|
|
except ValueError:
|
|
raise ArgumentTypeError(f'Not an octal mode: {s}')
|
|
|
|
class CmdCompileTemplates(Cmd): # export
|
|
|
|
def __init__(self, parent: Parent) -> None:
|
|
super().__init__(
|
|
parent, 'compile-templates', help = 'Compile package template files'
|
|
)
|
|
|
|
@override
|
|
async def _run(self, args: Namespace) -> None:
|
|
attrs = Attrs(args.mode, args.owner, args.group, None)
|
|
await self._compile_template_files(args.packages, attrs, args.keep_going)
|
|
|
|
@override
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
super().add_arguments(parser)
|
|
parser.add_argument(
|
|
'--keep-going',
|
|
'-k',
|
|
action = 'store_true',
|
|
help = 'Compile all templates, reporting the failures at the end',
|
|
)
|
|
parser.add_argument(
|
|
'--owner', '-o', default = None, help = 'Default output file owner'
|
|
)
|
|
parser.add_argument(
|
|
'--group', '-g', default = None, help = 'Default output file group'
|
|
)
|
|
parser.add_argument(
|
|
'--mode',
|
|
'-m',
|
|
default = None,
|
|
type = octal_mode,
|
|
help = 'Default output file mode (octal)',
|
|
)
|