qbt-clean 0.120.0

Automated rules-based cleaning of qBittorrent torrents.
use anyhow::Context as _;

#[derive(Debug,clap::Args)]
#[group(required=true)]
pub struct ArgsConfig {
	/// Path to config in simple-config format.
	#[clap(short, long)]
	config: Option<std::path::PathBuf>,

	/// Path to config in JSON format.
	#[clap(short, long)]
	json: Option<std::path::PathBuf>
}

impl ArgsConfig {
	pub fn read(&self) -> anyhow::Result<crate::Config> {
		Ok(if let Some(path) = &self.config {
			simple_config::from_file(path)
				.with_context(|| format!("Reading config from {:?}", path))?
		} else if let Some(path) = &self.json {
			let f = std::fs::File::open(path)
				.with_context(|| format!("Reading config from {:?}", path))?;
			serde_json::from_reader(f)?
		} else {
			unreachable!()
		})
	}
}