Skip to content

Commit

Permalink
fix: changed dependency from wild to glob
Browse files Browse the repository at this point in the history
To avoid the issue of wild,
[On Windows, `.\dir\ -f` parsed as one arg instead of 2 (#7)](https://gitlab.com/kornelski/wild/-/issues/7)
remove dependency to wild and introduce glob.
  • Loading branch information
urin committed Jan 29, 2023
1 parent 0156d7b commit fe63028
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
11 changes: 1 addition & 10 deletions 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
Expand Up @@ -18,5 +18,5 @@ clap = { version = "4.0.32", features = ["derive"] }
colored = "2.0.0"
edit = "0.1.4"
fs_extra = "1.2.0"
glob = "0.3.1"
normpath = "1.0.1"
wild = "2.1.0"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

- Displays file and directory names like [`ls`](https://man7.org/linux/man-pages/man1/ls.1.html) in a text editor,
and renames or moves them exactly as you edit them.
- Aborts entire operation in case of collisions.
- Supports Linux, Mac, and Windows.
- Supports wildcard patterns including Windows.
- Aborts operation in case of collisions.

### Caveats ⚠

Expand Down
28 changes: 27 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ pub fn try_main(args: &CommandLine) -> Result<usize> {

fn sources_from(args: &CommandLine) -> Result<Vec<Source>> {
let mut sources: Vec<Source> = Vec::new();
for p in args.paths.iter().map(|p| p.trim_end_matches(SEPARATORS)) {
let paths = arg_paths(&args.paths)?;
for p in paths.iter().map(|p| p.trim_end_matches(SEPARATORS)) {
let path = &PathBuf::from(if cfg!(target_family = "windows") {
p.replace('/', "\\")
} else {
Expand Down Expand Up @@ -113,6 +114,31 @@ fn sources_from(args: &CommandLine) -> Result<Vec<Source>> {
Ok(sources)
}

fn arg_paths(args: &Vec<String>) -> Result<Vec<String>> {
use glob::glob;
let mut paths = Vec::new();
for arg in args.iter() {
let mut globbed = Vec::new();
for path in
glob(arg).with_context(|| format!("Invalid pattern {}", arg.yellow().underline()))?
{
globbed
.push(path.with_context(|| format!("Failed to glob {}", arg.yellow().underline()))?)
}
if globbed.is_empty() {
anyhow::bail!("Failed to access {}", arg);
}
globbed.sort_unstable_by(|a, b| a.canonicalize().unwrap().cmp(&b.canonicalize().unwrap()));
paths.append(
&mut globbed
.iter()
.map(|g| g.to_string_lossy().to_string())
.collect(),
);
}
Ok(paths)
}

fn put_source(sources: &mut Vec<Source>, path: &Path, args: &CommandLine) -> Result<()> {
let normalized = normalize(path)?;
if normalized.parent().is_err() {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use colored::*;

#[doc(hidden)]
fn main() -> Result<()> {
let args = CommandLine::parse_from(wild::args());
let args = CommandLine::parse();
match try_main(&args) {
Err(err) => {
if !args.quiet {
eprintln!("{} {:?}", "Error:".bright_red().bold(), err);
}
std::process::exit(2);
},
}
Ok(processed) => {
if !args.quiet {
if processed == 0 {
Expand Down

0 comments on commit fe63028

Please sign in to comment.