Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #95 from h-michael/globwalk
Browse files Browse the repository at this point in the history
Use globwalk instead of glob
  • Loading branch information
killercup committed Oct 7, 2018
2 parents 58503d6 + fe71e21 commit 31862d2
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
76 changes: 75 additions & 1 deletion Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ keywords = ["cli", "prelude"]
[dependencies]
failure = "0.1.2"
failure_derive = "0.1.2"
serde = { version="1.0.27", optional = true}
serde_derive = { version="1.0.27", optional = true }
serde = { version = "1.0.27", optional = true}
serde_derive = { version = "1.0.27", optional = true }
structopt = "0.2.8"
structopt-derive = "0.2.8"
log = "0.4.1"
env_logger = "0.5.3"
glob = { version = "0.2.11", optional = true }
globwalk = { version = "0.3", optional = true }
rayon = { version = "1.0", optional = true }
clap-verbosity-flag = "0.1.0"

Expand All @@ -31,7 +31,7 @@ default = ["full-throttle"]
full-throttle = [
"serde",
"serde_derive",
"glob",
"globwalk",
"rayon",
]

Expand Down
22 changes: 12 additions & 10 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! These are rather simple, but provide a quick and easy way to to common
//! tasks. Also, they have great error messages.

extern crate glob;
extern crate globwalk;

use std::path::{Path, PathBuf};
use std::io::{BufReader, BufWriter, Read, Write};
Expand Down Expand Up @@ -91,25 +91,27 @@ pub fn write_to_file<P: AsRef<Path>>(path: P, content: &str) -> Result<()> {
/// let markdown_files = glob("*.md")?;
/// assert_eq!(markdown_files.len(), 2);
///
/// let weird_files = glob("**/*.weird");
/// assert!(weird_files.is_err());
/// if let Err(e) = weird_files {
/// assert_eq!(e.to_string(), "No files match pattern `**/*.weird`".to_string());
/// let image_files = glob("**/*.{png,jpg,gif}");
/// assert!(image_files.is_err());
/// if let Err(e) = image_files {
/// assert_eq!(e.to_string(), "No files match pattern `**/*.{png,jpg,gif}`".to_string());
/// }
/// # Ok(()) }
/// ```
pub fn glob(pattern: &str) -> Result<Vec<PathBuf>> {
use self::glob::{glob_with, MatchOptions};
pub fn glob(patterns: &str) -> Result<Vec<PathBuf>> {
use self::globwalk::glob;

let options: MatchOptions = Default::default();
let files: Vec<_> = glob_with(pattern, &options)?
let files: Vec<_> = glob(patterns)?
.max_depth(1)
.into_iter()
.filter_map(StdResult::ok)
.map(|dir_entry| dir_entry.path().to_owned())
.collect();

ensure!(
files.get(0).is_some(),
"No files match pattern `{}`",
pattern
patterns
);

Ok(files)
Expand Down

0 comments on commit 31862d2

Please sign in to comment.