pub mod fetch;
pub mod info;
pub mod list_langs;
use anyhow::Result;
use clap::{Parser, Subcommand};
#[derive(Parser)]
pub struct YoutubeCommand {
#[command(subcommand)]
pub command: YoutubeSubcommands,
}
#[derive(Subcommand)]
pub enum YoutubeSubcommands {
Fetch(fetch::FetchCommand),
ListLangs(list_langs::ListLangsCommand),
Info(info::InfoCommand),
}
impl YoutubeCommand {
pub async fn execute(self) -> Result<()> {
match self.command {
YoutubeSubcommands::Fetch(cmd) => cmd.execute().await,
YoutubeSubcommands::ListLangs(cmd) => cmd.execute().await,
YoutubeSubcommands::Info(cmd) => cmd.execute().await,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::cli::transcript::format::CliFormat;
#[test]
fn youtube_subcommands_fetch_variant() {
let cmd = YoutubeCommand {
command: YoutubeSubcommands::Fetch(fetch::FetchCommand {
url: "https://youtu.be/abc".to_string(),
lang: "en".to_string(),
format: CliFormat::Srt,
auto: false,
translate: None,
output: None,
}),
};
assert!(matches!(cmd.command, YoutubeSubcommands::Fetch(_)));
}
#[test]
fn youtube_subcommands_list_langs_variant() {
let cmd = YoutubeCommand {
command: YoutubeSubcommands::ListLangs(list_langs::ListLangsCommand {
url: "https://youtu.be/abc".to_string(),
output: list_langs::ListLangsOutput::Table,
}),
};
assert!(matches!(cmd.command, YoutubeSubcommands::ListLangs(_)));
}
#[test]
fn youtube_subcommands_info_variant() {
let cmd = YoutubeCommand {
command: YoutubeSubcommands::Info(info::InfoCommand {
url: "https://youtu.be/abc".to_string(),
output: info::InfoOutput::Table,
}),
};
assert!(matches!(cmd.command, YoutubeSubcommands::Info(_)));
}
}