subx_cli/cli/
convert_args.rs

1// src/cli/convert_args.rs
2use clap::{Args, ValueEnum};
3use std::path::PathBuf;
4
5/// 格式轉換參數
6#[derive(Args, Debug)]
7pub struct ConvertArgs {
8    /// 輸入檔案或資料夾路徑
9    pub input: PathBuf,
10
11    /// 目標格式 (預設值由配置檔案指定)
12    #[arg(long, value_enum)]
13    pub format: Option<OutputSubtitleFormat>,
14
15    /// 輸出檔案路徑
16    #[arg(short, long)]
17    pub output: Option<PathBuf>,
18
19    /// 保留原始檔案
20    #[arg(long)]
21    pub keep_original: bool,
22
23    /// 文字編碼
24    #[arg(long, default_value = "utf-8")]
25    pub encoding: String,
26}
27
28/// 支援的輸出字幕格式
29#[derive(ValueEnum, Clone, Debug)]
30pub enum OutputSubtitleFormat {
31    Srt,
32    Ass,
33    Vtt,
34    Sub,
35}
36
37impl OutputSubtitleFormat {
38    /// 取得格式字串
39    pub fn as_str(&self) -> &'static str {
40        match self {
41            OutputSubtitleFormat::Srt => "srt",
42            OutputSubtitleFormat::Ass => "ass",
43            OutputSubtitleFormat::Vtt => "vtt",
44            OutputSubtitleFormat::Sub => "sub",
45        }
46    }
47}
48
49impl std::fmt::Display for OutputSubtitleFormat {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        write!(f, "{}", self.as_str())
52    }
53}