use ddns_a::config::{ConfigError, field};
use tracing::Level;
use tracing_subscriber::EnvFilter;
pub mod exit_code {
use std::process::ExitCode;
pub const SUCCESS: ExitCode = ExitCode::SUCCESS;
pub const CONFIG_ERROR: ExitCode = ExitCode::FAILURE;
pub fn runtime_error() -> ExitCode {
ExitCode::from(2)
}
}
pub fn print_config_hint(error: &ConfigError) {
match error {
ConfigError::MissingRequired { field: f, .. } => {
if *f == field::URL || *f == field::IP_VERSION {
eprintln!("\nRun 'ddns-a init' to generate a configuration template.");
}
}
ConfigError::FileRead { .. } => {
eprintln!("\nRun 'ddns-a init' to generate a configuration template.");
}
_ => {}
}
}
pub fn setup_tracing(verbose: bool) {
let level = if verbose { Level::DEBUG } else { Level::INFO };
let filter = EnvFilter::builder()
.with_default_directive(level.into())
.from_env_lossy();
tracing_subscriber::fmt()
.with_env_filter(filter)
.with_target(false)
.init();
}