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

implemented filelist to get list of paths #2598

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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