add filter to diff

master
Rasmus Rosengren 2 years ago
parent 70286c0a9a
commit 811b20e171
Signed by: rsrp
SSH Key Fingerprint: SHA256:vdAo4Qg/MlIkxR5BRTABqMRJ1sGSVlUcIciriaE3cNU
  1. 17
      src/diff.rs
  2. 4
      src/main.rs
  3. 7
      src/opts.rs

@ -4,10 +4,21 @@ use terminal_size::{terminal_size, Width};
use crate::{context::Context, utils::get_tree_files}; use crate::{context::Context, utils::get_tree_files};
pub fn diff(context: &Context) -> anyhow::Result<()> { pub fn diff(context: &Context, filter: &Option<String>) -> anyhow::Result<()> {
std::fs::create_dir_all(&context.install_dir)?; std::fs::create_dir_all(&context.install_dir)?;
let built_files = get_tree_files(context, &context.build_dir)?; let mut built_files = get_tree_files(context, &context.build_dir)?;
let installed_files = get_tree_files(context, &context.install_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!("Built files: {:#?}", built_files);
log::debug!("Installed files: {:#?}", installed_files); log::debug!("Installed files: {:#?}", installed_files);

@ -35,11 +35,11 @@ fn main() -> anyhow::Result<()> {
apply(&context, &filter, link).expect("Failed to apply"); 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); let context = build_context(repo_path);
log::debug!("Context: {:#?}", context); log::debug!("Context: {:#?}", context);
build(&context).expect("Failed to build"); build(&context).expect("Failed to build");
diff(&context).expect("Failed to diff"); diff(&context, &filter).expect("Failed to diff");
} }
opts::Commands::GenerateCompletions { shell } => { opts::Commands::GenerateCompletions { shell } => {
generate(shell, &mut Opts::command(), "dfm", &mut std::io::stdout()); generate(shell, &mut Opts::command(), "dfm", &mut std::io::stdout());

@ -27,7 +27,9 @@ pub enum Commands {
)] )]
repo_path: PathBuf, 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<String>, filter: Option<String>,
#[clap(short, long, default_value = "true", help = "Symlink the built files")] #[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" help = "Path to source repo, absolute path or path relative to $HOME"
)] )]
repo_path: PathBuf, repo_path: PathBuf,
#[clap(help = "Filter which files should be diffed, checks if if path starts with this")]
filter: Option<String>,
}, },
#[clap(about = "Generate shell completions")] #[clap(about = "Generate shell completions")]
GenerateCompletions { GenerateCompletions {

Loading…
Cancel
Save