use crate::prelude::*;
use humantime::parse_duration;
#[derive(Options, Clone, Debug, Deserialize, Serialize)]
#[allow(clippy::struct_excessive_bools)]
pub struct BatchOptions {
#[arg(long)]
pub spectrogram: bool,
#[arg(long)]
pub transcode: bool,
#[arg(long)]
pub retry_transcode: bool,
#[arg(long)]
pub upload: bool,
#[arg(long)]
#[options(default = 3)]
pub limit: usize,
#[arg(long)]
pub no_limit: bool,
#[arg(long)]
pub wait_before_upload: Option<String>,
}
impl BatchOptions {
#[must_use]
pub fn get_wait_before_upload(&self) -> Option<Duration> {
let wait_before_upload = self.wait_before_upload.clone()?;
parse_duration(wait_before_upload.as_str()).ok()
}
#[must_use]
pub fn get_limit(&self) -> Option<usize> {
if self.no_limit {
None
} else {
Some(self.limit)
}
}
}
impl OptionsContract for BatchOptions {
type Partial = BatchOptionsPartial;
fn validate(&self, validator: &mut OptionsValidator) {
if let Some(wait_before_upload) = &self.wait_before_upload
&& let Err(error) = parse_duration(wait_before_upload.as_str())
{
validator.push(OptionIssue::duration_invalid(
"wait_before_upload",
wait_before_upload,
&error.to_string(),
));
}
validator.check_dependent("upload", self.upload, "transcode", self.transcode);
}
}