diff --git a/src/diff.rs b/src/diff.rs index 8429101..b41d0e2 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -4,10 +4,21 @@ use terminal_size::{terminal_size, Width}; use crate::{context::Context, utils::get_tree_files}; -pub fn diff(context: &Context) -> anyhow::Result<()> { +pub fn diff(context: &Context, filter: &Option) -> anyhow::Result<()> { std::fs::create_dir_all(&context.install_dir)?; - let built_files = get_tree_files(context, &context.build_dir)?; - let installed_files = get_tree_files(context, &context.install_dir)?; + let mut built_files = get_tree_files(context, &context.build_dir)?; + let mut installed_files = get_tree_files(context, &context.install_dir)?; + if let Some(filter) = filter { + log::debug!("Using filter: {}", filter); + built_files = built_files + .into_iter() + .filter(|path| path.starts_with(filter)) + .collect(); + installed_files = installed_files + .into_iter() + .filter(|path| path.starts_with(filter)) + .collect(); + } log::debug!("Built files: {:#?}", built_files); log::debug!("Installed files: {:#?}", installed_files); diff --git a/src/main.rs b/src/main.rs index ba233f3..8d78960 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,11 +35,11 @@ fn main() -> anyhow::Result<()> { apply(&context, &filter, link).expect("Failed to apply"); } } - opts::Commands::Diff { repo_path } => { + opts::Commands::Diff { repo_path, filter } => { let context = build_context(repo_path); log::debug!("Context: {:#?}", context); build(&context).expect("Failed to build"); - diff(&context).expect("Failed to diff"); + diff(&context, &filter).expect("Failed to diff"); } opts::Commands::GenerateCompletions { shell } => { generate(shell, &mut Opts::command(), "dfm", &mut std::io::stdout()); diff --git a/src/opts.rs b/src/opts.rs index 142259d..da46937 100644 --- a/src/opts.rs +++ b/src/opts.rs @@ -27,7 +27,9 @@ pub enum Commands { )] repo_path: PathBuf, - #[clap(help = "Filter which files should be installed, checks for substring")] + #[clap( + help = "Filter which files should be installed, checks if if path starts with this" + )] filter: Option, #[clap(short, long, default_value = "true", help = "Symlink the built files")] @@ -42,6 +44,9 @@ pub enum Commands { help = "Path to source repo, absolute path or path relative to $HOME" )] repo_path: PathBuf, + + #[clap(help = "Filter which files should be diffed, checks if if path starts with this")] + filter: Option, }, #[clap(about = "Generate shell completions")] GenerateCompletions {