Skip to content

Commit

Permalink
implemented filelist to get list of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalk11 committed Aug 26, 2023
1 parent 962d47e commit cc69335
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/core/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
flag_engine(&mut args);
flag_field_context_separator(&mut args);
flag_field_match_separator(&mut args);
flag_file_list(&mut args);
flag_file(&mut args);
flag_files(&mut args);
flag_files_with_matches(&mut args);
Expand Down Expand Up @@ -1262,6 +1263,19 @@ character is the default value.
.long_help(LONG);
args.push(arg);
}
fn flag_file_list(args: &mut Vec<RGArg>) {
const SHORT: &str = "A file that contains list of paths to include";
const LONG: &str = long!(
"\
A file that contains list of paths to include
"
);
let arg = RGArg::flag("filelist", "FILE")
.help(SHORT)
.long_help(LONG)
.allow_leading_hyphen();
args.push(arg);
}

fn flag_file(args: &mut Vec<RGArg>) {
const SHORT: &str = "Search for patterns from the given file.";
Expand Down
28 changes: 28 additions & 0 deletions crates/core/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,27 @@ impl ArgMatches {
self.is_present("ignore-file-case-insensitive")
}

//returns list of paths written inside filelist
fn list_paths(&self) -> Vec<String> {
let path = self.value_of_os("filelist").unwrap();

use std::fs::File;
use std::io::BufRead;
// Open the file
//let file = File::open(Path::new(path));
// Create a buffer reader
let reader = io::BufReader::new(fs::File::open(Path::new(path)).unwrap());
// Collect the paths into a vector
let paths: Vec<String> = reader.lines()
.filter_map(|line| line.ok()) // Filter out any lines with read errors
.filter_map(|line| {
Some(line.trim().to_string()) // Extract the path and trim whitespace
})
.collect();

paths
}

/// Return all of the ignore file paths given on the command line.
fn ignore_paths(&self) -> Vec<PathBuf> {
let paths = match self.values_of_os("ignore-file") {
Expand Down Expand Up @@ -1321,6 +1342,13 @@ impl ArgMatches {
paths.insert(0, Path::new(path).to_path_buf());
}
}
if self.is_present("filelist")
{
let fnlist= self.list_paths();
for path in fnlist {
paths.push(Path::new(&path).to_path_buf());
}
}
paths
}

Expand Down

0 comments on commit cc69335

Please sign in to comment.