Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for glob patterns in quotes #536

Merged
merged 8 commits into from
Jul 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated apply_glob_pattern function
  • Loading branch information
SalOne22 committed Jul 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8124a6d2d721dbf7f810faeb81b993592741578d
27 changes: 13 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -295,7 +295,7 @@ Heuristic filter selection strategies:
8 => BigEnt Highest Shannon entropy of bigrams
9 => Brute Smallest compressed size (slow)",
)
.get_matches();
.get_matches_from(std::env::args());

let (out_file, out_dir, opts) = match parse_opts_into_struct(&matches) {
Ok(x) => x,
@@ -310,12 +310,8 @@ Heuristic filter selection strategies:
matches
.get_many::<PathBuf>("files")
.unwrap()
.flat_map(|path| {
apply_glob_pattern(path).unwrap_or_else(|e| {
warn!("{path:?}: {e}");
vec![]
})
})
.cloned()
.flat_map(apply_glob_pattern)
.collect(),
#[cfg(not(windows))]
matches
@@ -396,13 +392,16 @@ fn collect_files(
}

#[cfg(windows)]
fn apply_glob_pattern(path: &std::path::Path) -> Result<Vec<PathBuf>, String> {
let input_path = path.to_str().ok_or("Failed to read path.".to_string())?;

Ok(glob::glob(input_path)
.map_err(|e| e.to_string())?
.flatten()
.collect())
fn apply_glob_pattern(path: PathBuf) -> Vec<PathBuf> {
let matches = path
.to_str()
.and_then(|pattern| glob::glob(pattern).ok())
.map(|paths| paths.flatten().collect::<Vec<_>>());

match matches {
Some(paths) if !paths.is_empty() => paths,
_ => vec![path],
}
}

fn parse_opts_into_struct(