Skip to content

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
craftgear committed Aug 12, 2024
1 parent 54b18a8 commit e9eb320
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "group_files_into_dirs"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
license = "MIT"
description = "Group files into directories based on keywords"
Expand Down
28 changes: 28 additions & 0 deletions src/libs/extract_keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ fn extract_file_basename(filename: &String) -> String {
re.replace_all(filename, "").to_string()
}

// pub fn extract_keywords_from_camel_case(filename_wo_ext: &String) -> Vec<String> {
// let modified_string = filename_wo_ext
// .chars()
// .filter_map(|c: char| match c {
// 'a'..='z' => Some(c.to_string()),
// 'A'..='Z' => Some(format!(" {}", c)),
// ' ' => None,
// _ => Some(c.to_string()),
// })
// .collect::<String>();
//
// let keywords = modified_string
// .split(' ')
// .map(|x| x.to_string())
// .collect::<Vec<String>>();
// return keywords;
// }

fn extract_keywords(filename_wo_ext: &String) -> Vec<String> {
let filename_wo_ext = extract_file_basename(filename_wo_ext);
let re = Regex::new(PAREN_REGEX_STR).unwrap();
Expand Down Expand Up @@ -185,4 +203,14 @@ mod tests {
];
assert_eq!(result, expected);
}

// #[test]
// fn test_extract_keywords_from_camel_case() {
// let filename = "camelCase FileName Could BeParsed".to_string();
// let result = extract_keywords_from_camel_case(&filename);
// assert_eq!(
// result,
// vec!["camel", "Case", "File", "Name", "Could", "Be", "Parsed"]
// );
// }
}
1 change: 1 addition & 0 deletions src/libs/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub fn move_files_to_dir_by_keywords(
verbose: bool,
) -> Result<(), Error> {
let files = files_in_dir(&pathbuf)?;

match move_files_to_dir(&pathbuf, &files, &keywords, verbose) {
Ok(result) => {
if result.len() == 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn execute(pathbuf: &PathBuf) -> Result<Vec<String>, Error> {
println!("");
let mut sp = Spinner::new(
Spinners::CircleHalves,
"Extracting keywords with 3 or more charaters from filenames".into(),
"Extracting keywords with 2 or more charaters from filenames".into(),
);

let filenames = files_in_dir(&pathbuf)?;
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Parser;
use owo_colors::OwoColorize;
use std::path::Path;

mod libs;
Expand Down Expand Up @@ -29,6 +30,12 @@ fn main() -> Result<(), Error> {
verbose,
} = Args::parse();

if !Path::new(&path).exists() {
let msg = format!("Eroor: path {} does not exist", path);
println!("{}", msg.red());
return Ok(());
}

if let Some(keywords) = keywords {
return use_keywords(keywords, path, verbose);
}
Expand Down

0 comments on commit e9eb320

Please sign in to comment.