1 parent
f47217d5a3
commit
8ceb3c8be8
60 files changed
+10884
No files matched your search
@@ -0,0 +1,77 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::{Parser, Subcommand};
|
||||
use figment::Figment;
|
||||
use figment::providers::{Env, Format, Toml};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
const EXAMPLE_CONFIG: &str = include_str!("../../../config.example.toml");
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about = "Move media between two Jellyfin servers")]
|
||||
struct Cli {
|
||||
/// Config file (TOML). Values can be overridden with JELLYMOVE_* env vars.
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
env = "JELLYMOVE_CONFIG",
|
||||
default_value = "jellymove.toml",
|
||||
global = true
|
||||
)]
|
||||
config: PathBuf,
|
||||
/// Log as JSON lines (for log shippers).
|
||||
#[arg(long, env = "JELLYMOVE_LOG_JSON", global = true)]
|
||||
log_json: bool,
|
||||
#[command(subcommand)]
|
||||
command: Option<Command>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Command {
|
||||
/// Run the daemon (default).
|
||||
Run,
|
||||
/// Load and validate the config, print it with secrets redacted, then exit.
|
||||
CheckConfig,
|
||||
/// Print an example config file.
|
||||
ExampleConfig,
|
||||
}
|
||||
|
||||
fn load(path: &PathBuf) -> anyhow::Result<jm_server::Config> {
|
||||
let mut fig = Figment::new();
|
||||
if path.exists() {
|
||||
fig = fig.merge(Toml::file(path));
|
||||
} else {
|
||||
tracing::warn!(path = %path.display(), "config file not found; using environment only");
|
||||
}
|
||||
fig.merge(
|
||||
Env::prefixed("JELLYMOVE_")
|
||||
.split("__")
|
||||
.ignore(&["config", "log_json"]),
|
||||
)
|
||||
.extract()
|
||||
.with_context(|| format!("invalid configuration (file: {})", path.display()))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
let filter = EnvFilter::try_from_env("JELLYMOVE_LOG")
|
||||
.unwrap_or_else(|_| EnvFilter::new("info,tower_http=warn"));
|
||||
let fmt = tracing_subscriber::fmt().with_env_filter(filter);
|
||||
if cli.log_json {
|
||||
fmt.json().init()
|
||||
} else {
|
||||
fmt.init()
|
||||
}
|
||||
|
||||
match cli.command.unwrap_or(Command::Run) {
|
||||
Command::ExampleConfig => print!("{EXAMPLE_CONFIG}"),
|
||||
Command::CheckConfig => {
|
||||
let cfg = load(&cli.config)?;
|
||||
println!("{}", serde_json::to_string_pretty(&cfg.redacted())?);
|
||||
}
|
||||
Command::Run => jm_server::run(load(&cli.config)?).await?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user