Skip to content

Commit

Permalink
Supports pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
nokonoko1203 committed Dec 3, 2024
1 parent 5fa50ef commit ae7861d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ log = "0.4.22"
env_logger = "0.11.5"
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0.133"
glob = "0.3.1"
23 changes: 22 additions & 1 deletion app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use chrono::Local;
use env_logger::Builder;
use glob::glob;
use log::LevelFilter;

use pcd_core::pointcloud::{
Expand Down Expand Up @@ -72,6 +73,23 @@ fn check_and_get_extension(paths: &[PathBuf]) -> Result<Extension, String> {
Ok(get_extension(extensions[0]))
}

fn expand_globs(input_patterns: Vec<String>) -> Vec<PathBuf> {
let mut paths = Vec::new();
for pattern in input_patterns {
if pattern.contains('*') || pattern.contains('?') || pattern.contains('[') {
for entry in glob(&pattern).expect("Failed to read glob pattern") {
match entry {
Ok(path) => paths.push(path),
Err(e) => eprintln!("Error: {:?}", e),
}
}
} else {
paths.push(PathBuf::from(pattern));
}
}
paths
}

fn main() {
Builder::new()
.format(|buf, record| {
Expand All @@ -97,7 +115,10 @@ fn main() {
let start = std::time::Instant::now();

log::info!("start processing...");
let input_files = args.input.iter().map(PathBuf::from).collect::<Vec<_>>();
// let input_files = args.input.iter().map(PathBuf::from).collect::<Vec<_>>();
let input_files = expand_globs(args.input);
log::info!("Expanded input files: {:?}", input_files);

let output_path = PathBuf::from(args.output);
std::fs::create_dir_all(&output_path).unwrap();

Expand Down

0 comments on commit ae7861d

Please sign in to comment.