module

ArrJanitor::CLI

Command-line entrypoint: parses the config path, loads + validates the config, builds a Backend per configured backend, and hands them to the Scheduler.

The loading/building steps are factored into load_config and build_backends so they can be unit-tested without starting the (long running) scheduler.

Constants

DEFAULT_CONFIG = "config.yml"

Config path used when neither --config/-c nor a bare positional is given — a config.yml in the current working directory.

LOG = ::Log.for("arr_janitor.cli")

Log source for CLI-phase messages (config load, backend construction). These run on the main fiber before the scheduler exists, so they go straight to Log rather than through the worker Reporter.

LOG_LEVEL_ENV = "ARR_JANITOR_LOG_LEVEL"

Environment variable holding the log level. Sits below -l/--log-level but above the config's log_level: in the precedence chain.

USAGE = "usage: arr_janitor [<config.yml> | -c|--config <path>] [-D|--database <path>] [-l|--log-level <level>] [-d|--daemon] [-n|--dry-run] [-h|--help] [-v|--version]"

One-line usage string, printed for -h/--help and on parse errors.

VALUE_FLAGS = {"--config", "-c", "--database", "-D", "--log-level", "-l"}

The value-taking flags. The argument immediately after one of these is that flag's value, so it must never be mistaken for the bare positional config path (nor for a boolean flag). Note the case distinction: -D is --database (a value flag) while -d is --daemon (a boolean flag).

Class methods

build_backends(config : Config) : Array(Backend)

Builds a concrete Backend for each configured backend. sonarr backends become SonarrBackends and radarr backends become RadarrBackends. Returns the built backends.

Source
build_store(dry_run : Bool, path : String) : Store | Nil

Selects the Store for this run: nil in dry-run (strictly read-only, so no database file is created), otherwise the store opened (creating if necessary) at path. Factored out so the store wiring is unit-testable without starting the scheduler.

Source
config_path(argv : Array(String)) : String

The resolved config path from argv: an explicit --config/-c value or, failing that, the first bare positional argument, defaulting to DEFAULT_CONFIG. The argument following any value flag (e.g. a -D/ --database path) is skipped, never returned as the config path.

Source
daemon?(argv : Array(String)) : Bool

Whether argv requests daemon (continuous) mode via --daemon/-d. When absent the CLI runs a single scan pass and exits.

Source
database_arg(argv : Array(String)) : String | Nil

The --database/-D override from argv, or nil when absent. When set it takes precedence over the config's database: value. The value after a -c/--config is skipped so a config path that happens to look like -D is not mistaken for this flag.

Source
dry_run?(argv : Array(String)) : Bool

Whether argv requests a dry run via --dry-run/-n. Combined with the config's own dry_run (either enables it) in run.

Source
help?(argv : Array(String)) : Bool

Whether argv requests the usage message via --help/-h.

Source
load_config(path : String) : Config

Loads and validates the config at path. Raises Config::Error on a missing/unparseable file or a validation failure.

Source
log_level_arg(argv : Array(String)) : String | Nil

The --log-level/-l value from argv, or nil when absent. The value after another value flag (e.g. a -c/--config path) is skipped so it is never mistaken for the log level. -l is distinct from -d/-D/-n.

Source
resolve_log_level(argv : Array(String), config : Config) : Log::Severity

Resolves the effective log level from argv and config, applying the precedence (highest first): -l/--log-levelARR_JANITOR_LOG_LEVEL env → config log_level:Info. The first non-blank source wins and is parsed via ArrJanitor.parse_log_level?; an invalid value from that source prints a clear error to STDERR listing the valid levels and exits 1 (matching how run handles config/store errors) rather than silently falling back. Returns Info when every source is nil/blank.

Source
run(argv : Array(String)) : Nil

Parses argv, loads + validates the config, builds the backends and runs the scheduler. Prints config errors to STDERR and exits non-zero.

Source
version?(argv : Array(String)) : Bool

Whether argv requests the version via --version/-v. When present the CLI prints arr_janitor <VERSION> and exits before any config loading.

Source