omni_dev/cli/transcript/youtube/
mod.rs1pub mod fetch;
4pub mod info;
5pub mod list_langs;
6
7use anyhow::Result;
8use clap::{Parser, Subcommand};
9
10#[derive(Parser)]
12pub struct YoutubeCommand {
13 #[command(subcommand)]
15 pub command: YoutubeSubcommands,
16}
17
18#[derive(Subcommand)]
20pub enum YoutubeSubcommands {
21 Fetch(fetch::FetchCommand),
23 ListLangs(list_langs::ListLangsCommand),
25 Info(info::InfoCommand),
27}
28
29impl YoutubeCommand {
30 pub async fn execute(self) -> Result<()> {
32 match self.command {
33 YoutubeSubcommands::Fetch(cmd) => cmd.execute().await,
34 YoutubeSubcommands::ListLangs(cmd) => cmd.execute().await,
35 YoutubeSubcommands::Info(cmd) => cmd.execute().await,
36 }
37 }
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43 use crate::cli::transcript::format::CliFormat;
44
45 #[test]
46 fn youtube_subcommands_fetch_variant() {
47 let cmd = YoutubeCommand {
48 command: YoutubeSubcommands::Fetch(fetch::FetchCommand {
49 url: "https://youtu.be/abc".to_string(),
50 lang: "en".to_string(),
51 format: CliFormat::Srt,
52 auto: false,
53 translate: None,
54 output: None,
55 }),
56 };
57 assert!(matches!(cmd.command, YoutubeSubcommands::Fetch(_)));
58 }
59
60 #[test]
61 fn youtube_subcommands_list_langs_variant() {
62 let cmd = YoutubeCommand {
63 command: YoutubeSubcommands::ListLangs(list_langs::ListLangsCommand {
64 url: "https://youtu.be/abc".to_string(),
65 output: list_langs::ListLangsOutput::Table,
66 }),
67 };
68 assert!(matches!(cmd.command, YoutubeSubcommands::ListLangs(_)));
69 }
70
71 #[test]
72 fn youtube_subcommands_info_variant() {
73 let cmd = YoutubeCommand {
74 command: YoutubeSubcommands::Info(info::InfoCommand {
75 url: "https://youtu.be/abc".to_string(),
76 output: info::InfoOutput::Table,
77 }),
78 };
79 assert!(matches!(cmd.command, YoutubeSubcommands::Info(_)));
80 }
81}