Skip to content

comicbox.cli ΒΆ

Cli for comicbox.

get_args(params=None) ΒΆ

Parse CLI arguments into the config namespace.

Config-tree args carry dotted dests naming their template path; set_args(dots=True) nests them. params is an argv-style sequence: params[0] is treated as the program name and dropped before parsing, mirroring sys.argv. Pass None to parse sys.argv itself.

Source code in comicbox/cli/__init__.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def get_args(params: Sequence[str] | None = None) -> Namespace:
    """
    Parse CLI arguments into the config namespace.

    Config-tree args carry dotted dests naming their template path;
    ``set_args(dots=True)`` nests them. ``params`` is an argv-style
    sequence: ``params[0]`` is treated as the program name and dropped
    before parsing, mirroring ``sys.argv``. Pass ``None`` to parse
    ``sys.argv`` itself.
    """
    parser = build_parser()
    if params is not None:
        params = params[1:]
    cns = parser.parse_args(params)
    # --id is single-comic only; mass-tagging would mistag.
    explicit_ids = getattr(cns, "explicit_ids", None) or ()
    if explicit_ids and len(cns.paths or ()) > 1:
        parser.error("--id requires exactly one input path")
    return cns

main(params=None) ΒΆ

Get CLI arguments and perform the operation on the archive.

Source code in comicbox/cli/__init__.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
def main(params: Sequence[str] | None = None) -> None:
    """Get CLI arguments and perform the operation on the archive."""
    argv = sys.argv if params is None else params
    if len(argv) > 1 and argv[1] == "doctor":
        # Before the Runner: building it resolves the config, which raises
        # on a bad one, and the doctor has to survive that to report it.
        # Imported here so a normal run never loads the doctor.
        from comicbox import doctor

        sys.exit(doctor.main(argv[2:]))
    if len(argv) > 1 and argv[1] in _READING_LIST_COMMANDS:
        # Its own parser and actions. Imported here so a normal run never
        # loads the reading-list package.
        from comicbox.readinglists import cli as readinglist_cli

        sys.exit(readinglist_cli.main(argv[2:]))
    cns = get_args(params)
    args = Namespace(comicbox=cns)

    try:
        # Building the runner resolves the config, so it's guarded too.
        runner = Runner(args)
        runner.run()
    except _HANDLED_EXCEPTIONS as exc:
        # Escaped: comic paths carry brackets ("[digital]") that rich
        # would otherwise swallow as markup, or reject outright.
        rich_print(f"[yellow]{escape(str(exc))}[/yellow]")
        sys.exit(1)
    if runner.failure_count:
        # Batch dispatch logs each failure and keeps going, so without
        # this a run where every file failed still exited 0. Serial runs
        # used to report it by letting the first failure escape, which
        # also abandoned every file behind it.
        rich_print(f"[yellow]{runner.failure_count} file(s) failed.[/yellow]")
        sys.exit(1)