Skip to content

Command-Line API

cli

Command-line interface for the Maraudarr generator.

main

main(arguments: list[str] | None = None) -> int

Run the Maraudarr command-line application.

Parameters:

Name Type Description Default
arguments list[str] | None

Optional argument vector excluding the executable name. Process arguments are used when this value is absent.

None

Returns:

Type Description
int

0 after a successful command, 1 after a catalog, rendering, or

int

operating-system failure, or 130 after intentional cancellation.

Note

Argument-parser usage errors and --version retain argparse's normal SystemExit behavior.

Source code in docker/src/maraudarr/cli.py
def main(arguments: list[str] | None = None) -> int:
    """Run the Maraudarr command-line application.

    Args:
        arguments: Optional argument vector excluding the executable name.
            Process arguments are used when this value is absent.

    Returns:
        ``0`` after a successful command, ``1`` after a catalog, rendering, or
        operating-system failure, or ``130`` after intentional cancellation.

    Note:
        Argument-parser usage errors and ``--version`` retain argparse's normal
        ``SystemExit`` behavior.
    """
    raw_arguments = list(sys.argv[1:] if arguments is None else arguments)
    # Accept --plain before or after the subcommand even though argparse defines
    # it globally, then restore the normalized flag on the parsed namespace.
    plain_requested = "--plain" in raw_arguments
    raw_arguments = [item for item in raw_arguments if item != "--plain"]
    arguments_namespace = _parser().parse_args(raw_arguments)
    arguments_namespace.plain = arguments_namespace.plain or plain_requested
    ui = UI(plain=arguments_namespace.plain)

    try:
        catalog = Catalog()
        command = arguments_namespace.command or "configure"

        if command == "presets":
            ui.welcome()
            ui.show_presets(list(catalog.presets.values()), catalog.services)
            return 0

        if command == "services":
            ui.welcome()
            ui.show_service_choices(
                sorted(catalog.services.values(), key=lambda item: item.order)
            )
            return 0

        if command == "build":
            plan = catalog.resolve(
                arguments_namespace.preset,
                add=_comma_set(arguments_namespace.add),
                remove=_comma_set(arguments_namespace.remove),
            )
            output_path = Path(arguments_namespace.output).resolve()
            return _write(catalog, plan, output_path, ui)

        plan = _interactive_plan(catalog, ui)
        output_path = Path(arguments_namespace.output).resolve()
        return _write(catalog, plan, output_path, ui)
    except UserCancelled as error:
        ui.cancelled(str(error))
        return 130
    except (CatalogError, RenderError, OSError) as error:
        ui.error(
            str(error),
            "Review the selected preset and service settings, then try again.",
        )
        return 1