Skip to content

Commit

Permalink
📦 Reduce select/2 to select/1 by usage of lazy_static
Browse files Browse the repository at this point in the history
  • Loading branch information
tgotwig committed Jul 18, 2024
1 parent 468654d commit 4fa1b25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions src/commanders/selector.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf>, Vec<String>, 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<PathBuf>, Vec<String>, 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);
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4fa1b25

Please sign in to comment.