ArrTop::CLI
Command-line entry point: resolves the config path, loads + validates the
config, sets up logging, builds a Backend per configured entry, then either
runs the live TUI (TUI) or prints a one-shot snapshot of the queue.
The default is the TUI when stdout is a terminal; a piped/redirected stdout
(or --once/-1) falls back to the plain-text snapshot. The path resolution
and backend construction are factored into config_path/build_backends so
they can be unit-tested without touching the network or the process exit.
Constants
Environment variable naming the config file, consulted after --config
but before the current-directory default search.
Config filenames searched (in order) in the current working directory when
neither --config/-c nor ARR_TOP_CONFIG is given.
Log source for CLI-phase messages (config load, backend construction,
poll summary). Scoped like the other arrtop.<area> sources.
Width the media (movie/series) name column is truncated to in the snapshot.
Width the SIZE column (the per-side disk / total pair) is right-aligned to
in the snapshot, e.g. 44 MB / 2.1 GB / 1.5 GB / 2.1 GB.
System-wide config paths searched (in order) after the current-directory
defaults. A local ./config.* therefore overrides a system one. This is
where the native package (.deb/.rpm) directs operators to place their
config (copied from the shipped config.yaml.example).
Width the torrent (release title) column is truncated to in the snapshot.
Usage text for -h/--help.
Flags that consume the following argument as their value. The argument
after one of these is that flag's value and must never be mistaken for
something else while scanning argv.
Class methods
Builds a concrete Backend for each configured entry: sonarr → a
SonarrBackend, radarr → a RadarrBackend. Order is preserved. A nil
type cannot occur post-validation but is skipped defensively.
The --config/-c value from argv, or nil when the flag is absent.
The argument after any value flag is skipped so it is never misread.
The resolved config path, or nil when none is found. Precedence:
-c/--config <path> → $ARR_TOP_CONFIG (if non-blank) → the first
existing of the current-directory defaults → the first existing of the
/etc/arr_top system-wide defaults → nil. A local ./config.* thus
overrides a system one.
The ordered list of config-file candidates tried when neither --config
nor $ARR_TOP_CONFIG selects a path: the current-directory defaults
first, then the /etc/arr_top system-wide fallbacks. Pure — it consults
no filesystem and no environment, so the search order is unit-testable.
The IMPORT% cell for a resolved display progress: the copy percentage
(e.g. 26.0%, or 100.0% for a finished season-pack episode), or — when
there is no progress to show (non-importing rows, pending episodes, and
importing rows arrtop cannot watch). Pure, so it's unit-testable.
Parses argv, loads + validates the config, polls every backend once and prints a snapshot. Errors are written to STDERR and exit non-zero.
The plain-text snapshot header line: the column labels aligned to the same
columns as snapshot_row. Pure/ANSI-free, so it's unit-testable.
One plain-text snapshot data line for row at effective display state, the
combined disk/total size pair, and resolved import progress: media ·
torrent · status · size (right-aligned human_size_pair) · DL% · IMPORT%.
Pure and ANSI-free, so it's unit-testable and safe for a piped/--once stdout.
Whether to run the interactive TUI: stdout is a terminal and --once/-1
was not passed.