Add CLI flag surface: -rename/--format/--db/--action/--conflict/-non-strict/-h

Ports FileBot's net.filebot.cli flag surface so Aurora Curator can be scripted,
not just driven through the GUI. Argument parsing and file-expansion are pure
Rust in aurora-curator-core::cli (14 unit tests, no Tauri/network dependency);
orchestration lives in src-tauri/src/cli.rs, which reuses the exact same
binding vocabulary the GUI's RenamePanel.tsx builds client-side and the exact
same TMDB/TVmaze season-caching lookup fetch_metadata already uses, so a
naming scheme renders identically whether it's typed into the app or passed
via --format.

main.rs branches to CLI mode before any Tauri App/window is built at all,
using tauri::async_runtime::block_on to drive the async metadata lookups
(confirmed safe standalone by reading Tauri's own async_runtime.rs) and a
hand-rolled settings::cli_tmdb_token() that replicates Tauri's own
app_config_dir() computation (dirs::config_dir().join(identifier), pinned
against tauri.conf.json by a new test) so a token saved through the GUI's
Fetch Data Settings is found from the CLI path too - the CLI still never
accepts a token as an argument.

Deliberately not ported: --output <dir> (the rename engine's safety
invariant against escaping the source directory tree would need to be
relaxed) and -non-strict is accepted as a no-op (local matching has no
confidence score to loosen).

16 new tests in src-tauri (10 in cli.rs, 1 pinning settings::
APP_CONFIG_IDENTIFIER) plus 14 in aurora-curator-core's cli module - full
workspace suite is 113 passing. README updated with a new "Command-line
usage" section and roadmap item 6 marked done for the CLI surface.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QLbx8ov7zMcdDPEqQm4Y98
This commit is contained in:
Renamr Scaffold
2026-08-29 11:30:51 +00:00
co-authored by Claude Sonnet 5
parent 5763c6313b
commit 22a3da9f6f
9 changed files with 1108 additions and 26 deletions
+50 -5
View File
@@ -1,17 +1,30 @@
//! Small persisted app settings - the TMDB API token, and (since the TVmaze datasource
//! was added) which TV metadata source Fetch Data should use ("Fetch Data" is the only
//! thing in the app that needs settings at all; everything else works offline). Stored
//! as plain JSON in Tauri's per-OS app config directory (e.g.
//! `~/Library/Application Support/com.auroracurator.app/settings.json` on macOS,
//! `~/.config/aurora-curator/settings.json` on Linux) - not the original FileBot's config
//! location, since that's Java Preferences-backed and OS/JVM-specific; this is Aurora Curator's
//! own, analogous location for its own settings.
//! as plain JSON in the OS's standard per-app config directory, joined with the app's
//! bundle identifier - `~/Library/Application Support/com.auroracurator.app/settings.json`
//! on macOS, `~/.config/com.auroracurator.app/settings.json` on Linux, `%APPDATA%\
//! com.auroracurator.app\settings.json` on Windows - not the original FileBot's config
//! location, since that's Java Preferences-backed and OS/JVM-specific; this is Aurora
//! Curator's own, analogous location for its own settings.
//!
//! The GUI reaches that directory through a running Tauri `AppHandle`
//! (`app.path().app_config_dir()`); the `-rename` CLI mode (`cli.rs`) never builds a
//! Tauri app at all, so it needs the exact same directory computed a different way -
//! see [`cli_tmdb_token`] below, which replicates Tauri's own `dirs::config_dir()
//! .join(identifier)` computation directly (confirmed against Tauri 2.11's
//! `path/desktop.rs` source) so both code paths are guaranteed to read/write the same
//! file. [`APP_CONFIG_IDENTIFIER`] must be kept in sync with `tauri.conf.json`'s
//! `identifier` field by hand - there's no way to share a constant with the JSON config.
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use tauri::{AppHandle, Manager};
/// Must match `tauri.conf.json`'s `identifier` field exactly - see the module doc.
const APP_CONFIG_IDENTIFIER: &str = "com.auroracurator.app";
/// Which online source Fetch Data resolves TV episodes against. Movies always use
/// TMDB regardless of this setting - TVmaze doesn't have a movie catalog at all, so
/// there's nothing to pick between for the movie half of Fetch Data.
@@ -66,6 +79,20 @@ pub fn tmdb_token(app: &AppHandle) -> Option<String> {
load(app).tmdb_token.filter(|t| !t.trim().is_empty())
}
/// Same as [`tmdb_token`], but for the `-rename` CLI path, which has no `AppHandle` to
/// ask (it never builds a Tauri app at all - see `cli.rs`'s module doc). Resolves the
/// config directory itself using the identical `dirs::config_dir().join(identifier)`
/// computation Tauri's own `AppHandle::path().app_config_dir()` uses internally, so a
/// token saved through the GUI's Fetch Data Settings is found here too. Aurora Curator
/// still never accepts an API token as a CLI argument - `--db tmdb` only works once a
/// token has been saved through the app itself at least once.
pub fn cli_tmdb_token() -> Option<String> {
let dir = dirs::config_dir()?.join(APP_CONFIG_IDENTIFIER);
let contents = fs::read_to_string(dir.join("settings.json")).ok()?;
let settings: StoredSettings = serde_json::from_str(&contents).ok()?;
settings.tmdb_token.filter(|t| !t.trim().is_empty())
}
#[tauri::command]
pub fn get_tmdb_token(app: AppHandle) -> Option<String> {
tmdb_token(&app)
@@ -114,6 +141,24 @@ mod tests {
assert_eq!(serde_json::to_string(&TvMetadataSource::Tvmaze).unwrap(), "\"tvmaze\"");
}
#[test]
fn app_config_identifier_matches_tauri_conf_json() {
// `cli_tmdb_token()` recomputes the GUI's settings-file path by hand (no
// `AppHandle` available in `-rename` mode), so this constant has to be kept in
// sync with `tauri.conf.json`'s `identifier` field manually - see the module
// doc. There's no way to share a single source of truth between a Rust const
// and the JSON config, so this test at least pins the value we're relying on:
// a change to `tauri.conf.json` without a matching change here would silently
// make the CLI look in the wrong directory for a token the GUI already saved.
let conf = include_str!("../tauri.conf.json");
let parsed: serde_json::Value = serde_json::from_str(conf).unwrap();
assert_eq!(
parsed["identifier"].as_str(),
Some(APP_CONFIG_IDENTIFIER),
"APP_CONFIG_IDENTIFIER must match tauri.conf.json's identifier field"
);
}
#[test]
fn stored_settings_without_a_tv_metadata_source_field_still_deserializes() {
// Settings written before this field existed (just `{"tmdbToken": "..."}` or