prdoclib/commands/
scan.rs

1//! Implementation of the scan command.
2//!
3//! The scan command searches for files that could
4//! potentially be PRDOC files. It does not check the validity of the files and the scanning is
5//! solely done based on the filenames
6
7use crate::{docfile::DocFile, schema::Schema};
8use std::{env, path::PathBuf};
9
10/// Wrapper to the scan command
11pub struct ScanCmd;
12
13impl ScanCmd {
14	/// Run of the scan command
15	pub fn run(schema: Schema, directories: Vec<PathBuf>, all: bool) -> Vec<PathBuf> {
16		let current_dir = env::current_dir().expect("Failed retrieving the current dir !");
17		log::debug!("Current dir: {}", current_dir.display());
18
19		directories
20			.iter()
21			.flat_map(|directory| {
22				if let Ok(dir) = DocFile::find(schema.clone(), directory, !all) {
23					dir.collect()
24				} else {
25					eprint!("Invalid directory: {}", directory.display());
26					vec![]
27				}
28			})
29			.collect()
30	}
31}