Standalone CLI — parses argv, builds a Shield, and dispatches commands.
Constructs :class:ShieldConfig from config.yml, XDG conventions,
and environment variables, then routes each subcommand through the
:data:~.registry.COMMANDS registry. Commands that need standalone CLI
logic (prepare, run, setup) are handled directly here.
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)
|