Standalone CLI — parses argv, builds a Shield, and dispatches commands.
Constructs ShieldConfig from config.yml, XDG conventions, and
environment variables, then routes each subcommand through the
COMMANDS registry (terok_shield.commands). Five commands with standalone
CLI logic are handled directly by _dispatch — setup and logs
(which bypass Shield entirely) and prepare, run, resolve
(which need Shield but carry extra CLI concerns). All others delegate
to their registry handler via Shield (the public API facade).
main(argv=None)
Run the terok-shield CLI.
Source code in src/terok_shield/cli/main.py
| def main(argv: list[str] | None = None) -> None:
"""Run the terok-shield CLI."""
if argv is None:
argv = sys.argv[1:]
# The 'run' subcommand uses '--' to separate shield args from podman args.
# Split before argparse to avoid REMAINDER quirks with optional flags.
saw_separator = "--" in argv
run_trailing: list[str] = []
if saw_separator:
sep = argv.index("--")
run_trailing = argv[sep + 1 :]
argv = argv[:sep]
parser = _build_parser()
args = parser.parse_args(argv)
if saw_separator and args.command != "run":
parser.error("'--' separator is only supported by the 'run' subcommand")
if args.command is None:
parser.print_help()
sys.exit(0)
if args.command == "run":
args.podman_args = run_trailing
try:
_dispatch(args)
except (RuntimeError, ValueError, ExecError, OSError) as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
|