use anyhow::Context;
use vqueue::{cli::args::Args, GenericQueueManager};
use vsmtp_config::Config;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = <Args as clap::Parser>::parse();
if args.version {
println!(
"{} v{}\ncommit: {}",
clap::crate_name!(),
clap::crate_version!(),
env!("GIT_HASH")
);
return Ok(());
}
if let Some(command) = args.command {
let config = args.config.as_ref().map_or_else(
|| Ok(Config::default()),
|path| Config::from_vsl_file(path).context("Cannot parse the configuration"),
)?;
let config = std::sync::Arc::new(config);
let manager = vqueue::fs::QueueManager::init(config)?;
command.execute(manager).await
} else {
anyhow::bail!("no commands where specified")
}
}