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
Config path used when neither --config/-c nor a bare positional is
given — a config.yml in the current working directory.
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.
Environment variable holding the log level. Sits below -l/--log-level
but above the config's log_level: in the precedence chain.
One-line usage string, printed for -h/--help and on parse errors.
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
Builds a concrete Backend for each configured backend. sonarr backends
become SonarrBackends and radarr backends become RadarrBackends.
Returns the built backends.
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.
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.
Whether argv requests daemon (continuous) mode via --daemon/-d.
When absent the CLI runs a single scan pass and exits.
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.
Whether argv requests a dry run via --dry-run/-n. Combined with the
config's own dry_run (either enables it) in run.
Loads and validates the config at path. Raises Config::Error on a
missing/unparseable file or a validation failure.
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.
Handles the informational flags that short-circuit before any config
loading: -h/--help prints USAGE and -v/--version prints the
version, each exiting 0. A no-op when neither flag is present.
Resolves the effective log level from argv and config, applying the
precedence (highest first): -l/--log-level → ARR_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.
Parses argv, loads + validates the config, builds the backends and runs the scheduler. Prints config errors to STDERR and exits non-zero.