diff --git a/Cargo.toml b/Cargo.toml index 3980b1c..9d25145 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ assert_cmd = "2.0.12" clap = {version = "3.2.25", features = ["derive"]} ctor = "0.1.26" k9 = "0.11.6" +lazy_static = "1.5.0" nanoid = "0.4.0" path-slash = "0.1.5" regex = "1" diff --git a/src/commanders/selector.rs b/src/commanders/selector.rs index ba126bd..dae17a3 100644 --- a/src/commanders/selector.rs +++ b/src/commanders/selector.rs @@ -1,11 +1,19 @@ +use crate::cli::Cli; use crate::helpers::io_helper::path_bufs_to_sorted_strings; use crate::helpers::io_helper::read_dir; use crate::helpers::str_helper::gen_input_file_content_for_ffmpeg; use crate::helpers::vec_helper::filter_files; +use clap::ArgMatches; +use lazy_static::lazy_static; use std::path::{Path, PathBuf}; -pub fn select(target_dir: &Path, file_format: &str) -> (Vec, Vec, String) { - let all_files_on_target_dir = read_dir(target_dir).unwrap(); +lazy_static! { + static ref MATCHES: ArgMatches = Cli::init().get_matches(); + static ref TARGET_DIR: &'static Path = Path::new(MATCHES.value_of("TARGET_DIR").unwrap()); +} + +pub fn select(file_format: &str) -> (Vec, Vec, String) { + let all_files_on_target_dir = read_dir(*TARGET_DIR).unwrap(); let files_to_merge = filter_files(all_files_on_target_dir, file_format); let files_to_merge_as_strings = path_bufs_to_sorted_strings(&files_to_merge); let ffmpeg_input_content = gen_input_file_content_for_ffmpeg(&files_to_merge_as_strings); diff --git a/src/main.rs b/src/main.rs index 9b6e16a..13a3338 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,7 +46,7 @@ fn main() -> Result<(), Error> { remove_file(&ffmpeg_output_file)?; let (files_to_merge, mut files_to_merge_as_strings, mut ffmpeg_input_content) = - select(target_dir, &file_format); + select(&file_format); if !ffmpeg_input_content.is_empty() { if verbose {