subx_cli/cli/
sync_args.rs1use clap::Args;
3use std::path::PathBuf;
4
5#[derive(Args, Debug)]
7pub struct SyncArgs {
8 pub video: PathBuf,
10
11 pub subtitle: PathBuf,
13
14 #[arg(long)]
16 pub offset: Option<f64>,
17
18 #[arg(long)]
20 pub batch: bool,
21
22 #[arg(long)]
24 pub range: Option<f32>,
25 #[arg(long)]
27 pub threshold: Option<f32>,
28}
29
30#[derive(Debug, Clone, PartialEq)]
32pub enum SyncMethod {
33 Auto,
35 Manual,
37}
38
39impl SyncArgs {
40 pub fn sync_method(&self) -> SyncMethod {
42 if self.offset.is_some() {
43 SyncMethod::Manual
44 } else {
45 SyncMethod::Auto
46 }
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_sync_method_selection_manual() {
56 let args = SyncArgs {
57 video: PathBuf::from("video.mp4"),
58 subtitle: PathBuf::from("subtitle.srt"),
59 offset: Some(2.5),
60 batch: false,
61 range: None,
62 threshold: None,
63 };
64 assert_eq!(args.sync_method(), SyncMethod::Manual);
65 }
66
67 #[test]
68 fn test_sync_method_selection_auto() {
69 let args = SyncArgs {
70 video: PathBuf::from("video.mp4"),
71 subtitle: PathBuf::from("subtitle.srt"),
72 offset: None,
73 batch: false,
74 range: None,
75 threshold: None,
76 };
77 assert_eq!(args.sync_method(), SyncMethod::Auto);
78 }
79}