diff --git a/README.md b/README.md index 11ce71b..cc147f6 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ gfold -d classic -c never ~/ --dry-run > $HOME/.config/gfold.toml Here are the contents of the resulting config file: ```toml -path = '/home/neloth' +paths = ['/home/neloth'] display_mode = 'Classic' color_mode = 'Never' ``` diff --git a/src/config.rs b/src/config.rs index 575f9f2..acde1cc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,8 +11,8 @@ use std::{env, fs}; /// deserialize empty, non-existent, partial, and complete config files. #[derive(Serialize)] pub struct Config { - /// The path that `gfold` will begin traversal in and collect results from. - pub path: PathBuf, + /// The paths that `gfold` will traverse and collect results from. + pub paths: Vec, /// The display format for results printed to `stdout`. pub display_mode: DisplayMode, /// The color mode for results printed to `stdout`. @@ -63,10 +63,24 @@ impl Config { } fn from_entry_config(entry_config: &EntryConfig) -> Result { + if entry_config.path.is_some() && entry_config.paths.is_some() { + return Err(anyhow::anyhow!( + "Cannot have both `path` and `paths` in config" + )); + } Ok(Config { - path: match &entry_config.path { - Some(path) => normalize_path(path)?, - None => env::current_dir()?.canonicalize()?, + paths: if let Some(paths) = &entry_config.paths { + paths + .iter() + .map(|p| normalize_path(p)) + .collect::, _>>()? + } else if let Some(path) = &entry_config.path { + println!( + "WARNING: the `path` configuration option is deprecated. Use `paths` instead." + ); + vec![normalize_path(path)?] + } else { + vec![env::current_dir()?.canonicalize()?] }, display_mode: match &entry_config.display_mode { Some(display_mode) => *display_mode, @@ -98,8 +112,11 @@ fn normalize_path(path: &Path) -> Result { /// this struct privately. #[derive(Deserialize, Default)] struct EntryConfig { - /// Reflection of the `path` field on [`Config`]. + /// Formerly a reflection of the `path` field on [`Config`]. Use `paths` instead. + /// This field is deprecated and will be removed in a future release. pub path: Option, + /// Reflection of the `paths` field on [`Config`]. + pub paths: Option>, /// Reflection of the `display_mode` field on [`Config`]. pub display_mode: Option, /// Reflection of the `color_mode` field on [`Config`]. diff --git a/src/main.rs b/src/main.rs index 3e3c832..d92c71a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use gfold::RepositoryCollector; use clap::Parser; use env_logger::Builder; use log::{debug, LevelFilter}; -use std::env; +use std::{env, path::PathBuf}; mod config; mod display; @@ -33,7 +33,7 @@ Troubleshooting: investigate unexpected behavior by prepending execution with \" #[command(version, about = HELP, long_about = None)] struct Cli { /// specify path to target directory (defaults to current working directory) - pub path: Option, + pub paths: Option>, #[arg(short, long)] pub color_mode: Option, @@ -73,8 +73,12 @@ fn main() -> anyhow::Result<()> { if let Some(found_color_mode) = &cli.color_mode { config.color_mode = *found_color_mode; } - if let Some(found_path) = &cli.path { - config.path = env::current_dir()?.join(found_path).canonicalize()?; + if let Some(found_paths) = &cli.paths { + let current_dir = env::current_dir()?; + config.paths = found_paths + .iter() + .map(|p| current_dir.join(p).canonicalize()) + .collect::, _>>()?; } debug!("finalized config options"); @@ -86,10 +90,14 @@ fn main() -> anyhow::Result<()> { DisplayMode::Json => (true, true), DisplayMode::Standard | DisplayMode::StandardAlphabetical => (true, false), }; - let repository_collection = - RepositoryCollector::run(&config.path, include_email, include_submodules)?; - let display_harness = DisplayHarness::new(config.display_mode, config.color_mode); - display_harness.run(&repository_collection)?; + for path in &config.paths { + debug!("processing path: {:?}", path); + + let repository_collection = + RepositoryCollector::run(path, include_email, include_submodules)?; + let display_harness = DisplayHarness::new(config.display_mode, config.color_mode); + display_harness.run(&repository_collection)?; + } } Ok(()) }