use clap::Parser;
#[derive(Parser, Debug, Clone)]
#[command(name = "voxtus")]
#[command(author, version, about, long_about = None)]
pub struct Args {
#[arg(required_unless_present = "list_models")]
pub input: Option<String>,
#[arg(short, long, default_value = "txt")]
pub format: String,
#[arg(short, long)]
pub name: Option<String>,
#[arg(short, long)]
pub output: Option<String>,
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
#[arg(short, long)]
pub keep: bool,
#[arg(long, default_value = "small")]
pub model: String,
#[arg(long)]
pub list_models: bool,
#[arg(long)]
pub overwrite: bool,
#[arg(long)]
pub stdout: bool,
}
impl Args {
pub fn parse_args() -> Self {
Self::parse()
}
pub fn parse_from_iter<I, T>(iter: I) -> Self
where
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
{
Self::parse_from(iter)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_basic_arguments() {
let args = Args::parse_from_iter(["voxtus", "test.mp3"]);
assert_eq!(args.input, Some("test.mp3".to_string()));
assert_eq!(args.format, "txt");
assert_eq!(args.verbose, 0);
assert!(!args.keep);
assert!(!args.overwrite);
assert!(!args.stdout);
assert_eq!(args.model, "small");
}
#[test]
fn test_parse_all_flags() {
let args = Args::parse_from_iter([
"voxtus",
"test.mp3",
"-v",
"-v",
"--keep",
"--overwrite",
"--format",
"json",
"--name",
"custom_name",
"--output",
"/tmp/output",
"--stdout",
"--model",
"tiny",
]);
assert_eq!(args.input, Some("test.mp3".to_string()));
assert_eq!(args.verbose, 2);
assert!(args.keep);
assert!(args.overwrite);
assert_eq!(args.format, "json");
assert_eq!(args.name, Some("custom_name".to_string()));
assert_eq!(args.output, Some("/tmp/output".to_string()));
assert!(args.stdout);
assert_eq!(args.model, "tiny");
}
#[test]
fn test_parse_short_flags() {
let args = Args::parse_from_iter([
"voxtus",
"test.mp3",
"-v",
"-k",
"-f",
"txt,json",
"-n",
"short_name",
"-o",
"/tmp/short",
]);
assert_eq!(args.input, Some("test.mp3".to_string()));
assert_eq!(args.verbose, 1);
assert!(args.keep);
assert_eq!(args.format, "txt,json");
assert_eq!(args.name, Some("short_name".to_string()));
assert_eq!(args.output, Some("/tmp/short".to_string()));
}
#[test]
fn test_list_models_without_input() {
let args = Args::parse_from_iter(["voxtus", "--list-models"]);
assert!(args.list_models);
assert!(args.input.is_none());
}
}