pub mod fetch;
pub mod format;
pub mod youtube;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser)]
pub struct TranscriptCommand {
#[command(subcommand)]
pub command: TranscriptSubcommands,
}
#[derive(Subcommand)]
pub enum TranscriptSubcommands {
Fetch(fetch::FetchCommand),
Youtube(youtube::YoutubeCommand),
}
impl TranscriptCommand {
pub async fn execute(self) -> Result<()> {
match self.command {
TranscriptSubcommands::Fetch(cmd) => cmd.execute().await,
TranscriptSubcommands::Youtube(cmd) => cmd.execute().await,
}
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
use crate::cli::transcript::format::CliFormat;
#[test]
fn transcript_subcommands_fetch_variant() {
let cmd = TranscriptCommand {
command: TranscriptSubcommands::Fetch(fetch::FetchCommand {
url: "https://youtu.be/dQw4w9WgXcQ".to_string(),
lang: "en".to_string(),
format: CliFormat::Srt,
auto: false,
translate: None,
output: None,
}),
};
assert!(matches!(cmd.command, TranscriptSubcommands::Fetch(_)));
}
#[tokio::test]
async fn fetch_dispatch_surfaces_unrecognised_locator() {
let cmd = TranscriptCommand {
command: TranscriptSubcommands::Fetch(fetch::FetchCommand {
url: "https://vimeo.com/76979871".to_string(),
lang: "en".to_string(),
format: CliFormat::Srt,
auto: false,
translate: None,
output: None,
}),
};
let err = cmd.execute().await.unwrap_err();
assert!(err.to_string().contains("invalid transcript locator"));
}
#[test]
fn transcript_subcommands_youtube_variant() {
let cmd = TranscriptCommand {
command: TranscriptSubcommands::Youtube(youtube::YoutubeCommand {
command: youtube::YoutubeSubcommands::Info(youtube::info::InfoCommand {
url: "https://youtu.be/dQw4w9WgXcQ".to_string(),
output: youtube::info::InfoOutput::Table,
}),
}),
};
assert!(matches!(cmd.command, TranscriptSubcommands::Youtube(_)));
}
}