Change the path argument to a PathBuf, and adjust the code accordingly.

This commit is contained in:
Pedro de Oliveira 2023-05-10 22:00:57 +01:00
parent 1d306c8c6c
commit b40e010b59
2 changed files with 8 additions and 7 deletions

View File

@ -6,9 +6,9 @@ use std::path::{Path, PathBuf};
///
/// # Arguments
///
/// * `path` - The path to the directory.
/// * `path` - A reference to a PathBuf representing the path to the directory.
/// * `wildcard` - The wildcard pattern to match against file names.
pub fn get_file_list(path: &str, wildcard: &str) -> Vec<String> {
pub fn get_file_list(path: &PathBuf, wildcard: &str) -> Vec<String> {
let pattern = Path::new(path).join(wildcard);
let dir_entries: Vec<Result<PathBuf, _>> = glob(&pattern.to_string_lossy()).unwrap().collect();
dir_entries
@ -108,16 +108,16 @@ fn full_name_test() {
#[test]
fn file_list_test() {
const DIRECTORY: &str = ".";
let directory = PathBuf::from(".");
const WILDCARD: &str = "*.toml";
assert_eq!(get_file_list(DIRECTORY, WILDCARD), vec!["Cargo.toml"]);
assert_eq!(get_file_list(&directory, WILDCARD), vec!["Cargo.toml"]);
}
#[test]
fn empty_file_list_test() {
const DIRECTORY: &str = "src";
let directory = PathBuf::from("src");
const WILDCARD: &str = "*.exe";
assert_eq!(get_file_list(DIRECTORY, WILDCARD), Vec::<String>::new());
assert_eq!(get_file_list(&directory, WILDCARD), Vec::<String>::new());
}

View File

@ -8,6 +8,7 @@
use clap::Parser;
use rmv::{get_file_list, replace_name};
use std::path::PathBuf;
/// Command line parser with clap
#[derive(Parser)]
@ -15,7 +16,7 @@ use rmv::{get_file_list, replace_name};
struct Args {
/// Path to the directory where the files to be renamed are located.
#[arg(short = 'i', long)]
path: String,
path: PathBuf,
/// Regular expression pattern to match against the file names in the directory.
///