Skip to content

Commit 3d39e42

Browse files
committed
feature: custom ignore path
1 parent 7434aad commit 3d39e42

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

sqlx-ts-common/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,8 @@ pub struct Cli {
6464
/// Primary DB database name
6565
#[clap(long)]
6666
pub db_name: Option<String>,
67+
68+
/// Folder paths to ignore
69+
#[clap(long, parse(from_os_str), multiple_values = true)]
70+
pub ignore: Vec<std::path::PathBuf>,
6771
}

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use clap::{ArgEnum, Args, Parser, Subcommand};
1010
use dotenv::dotenv;
1111
use sqlx_ts_common::cli::Cli;
1212
use sqlx_ts_core::execute::execute;
13+
use std::path::Path;
1314

1415
use crate::{parser::parse_source, scan_folder::scan_folder};
1516

@@ -19,16 +20,20 @@ fn main() {
1920
let cli_args = Cli::parse();
2021
let source_folder = &cli_args.path;
2122
let ext = &cli_args.ext;
23+
let ignore_paths = &cli_args.ignore;
24+
2225
println!(
2326
"Scanning {:?} for sqls with extension {:?}",
2427
source_folder, ext
2528
);
2629

27-
let files = scan_folder(&source_folder, ext);
30+
let files = scan_folder(&source_folder, ext, ignore_paths);
31+
32+
println!("checking files {:?}", files);
2833

2934
if files.is_empty() {
3035
println!("No targets detected, is it an empty folder?");
31-
return
36+
return;
3237
}
3338

3439
let explain_results: Vec<bool> = files

src/scan_folder.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@ use std::path::{Path, PathBuf};
33
use sqlx_ts_common::cli::JsExtension;
44
use walkdir::WalkDir;
55

6-
pub fn scan_folder<'a>(folder: &'a PathBuf, js_extension: &JsExtension) -> Vec<PathBuf> {
6+
pub fn scan_folder<'a>(
7+
folder: &'a PathBuf,
8+
js_extension: &'a JsExtension,
9+
ignore_paths: &'a Vec<PathBuf>,
10+
) -> Vec<PathBuf> {
711
let node_modules_path = folder.join(Path::new("node_modules"));
812
let path = Path::new(folder);
913
let result: Vec<_> = WalkDir::new(path)
1014
.follow_links(true)
1115
.into_iter()
1216
.filter_map(|e| e.ok())
1317
.filter(|entry| {
18+
// 1. ignore node modules
1419
if entry.path().starts_with(node_modules_path.as_path()) {
1520
return false;
1621
}
1722

23+
// 2. any custom ignore paths set by user should be ignored
24+
let should_ignore = ignore_paths
25+
.iter()
26+
.any(|ignore| entry.path().starts_with(ignore));
27+
if should_ignore {
28+
return false;
29+
}
30+
1831
let f_name = entry.file_name().to_string_lossy();
1932
if f_name.ends_with(js_extension.to_string().as_str()) {
2033
true

0 commit comments

Comments
 (0)