Created
September 30, 2019 20:25
-
-
Save dragonmaus/65aec98cdc163693c162ac2884bf0cc5 to your computer and use it in GitHub Desktop.
ignore bug test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
edition = "2018" | |
name = "test" | |
version = "0.0.0" | |
publish = false | |
description = "Test" | |
categories = ["command-line-utilities"] | |
license = "BSD-3-Clause-Clear" | |
[dependencies] | |
getopt = "0.4" | |
ignore = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use getopt::prelude::*; | |
use std::{env, error::Error, path::Path, process}; | |
fn main() -> ! { | |
process::exit(match program() { | |
Ok(code) => code, | |
Err(error) => { | |
eprintln!("{}", error); | |
1 | |
} | |
}); | |
} | |
fn program() -> Result<i32, Box<dyn Error>> { | |
let mut args = program_args(); | |
let mut opts = Parser::new(&args, "I:"); | |
let mut ignore_files: Vec<String> = Vec::new(); | |
loop { | |
match opts.next().transpose()? { | |
None => break, | |
Some(opt) => match opt { | |
Opt('I', Some(arg)) => ignore_files.push(arg), | |
_ => unreachable!(), | |
}, | |
} | |
} | |
let args = args.split_off(opts.index()); | |
for path in args { | |
let mut walker = ignore::WalkBuilder::new(&path); | |
for ignore_file in &ignore_files { | |
walker.add_ignore(ignore_file); | |
} | |
walker.standard_filters(false); | |
walker.sort_by_file_path(Path::cmp); | |
for entry in walker.build() { | |
let entry = entry?; | |
println!("{}", entry.path().display()); | |
} | |
} | |
Ok(0) | |
} | |
fn program_args() -> Vec<String> { | |
env::args_os() | |
.map(|a| a.to_string_lossy().into_owned()) | |
.collect() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment