diff --git a/Cargo.toml b/Cargo.toml index 3fd8436..746e55c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,14 @@ description = "A flexible rule-based file and folder comparison tool and crate i repository = "https://github.com/VolumeGraphics/havocompare" homepage = "https://github.com/VolumeGraphics/havocompare" documentation = "https://docs.rs/havocompare" -version = "0.5.3" +version = "0.5.4" edition = "2021" license = "MIT" authors = ["Volume Graphics GmbH"] exclude = ["tests/pdf", "tests/integ", "tests/html", "target", "tests/csv", ".github", "test_report"] keywords = ["diff" ,"compare", "csv", "image", "difference"] categories = ["filesystem"] +default-run = "havocompare" [[bin]] name = "print_args" diff --git a/README.md b/README.md index d8740e6..48af352 100644 --- a/README.md +++ b/README.md @@ -272,6 +272,9 @@ rules: ## Changelog +### 0.5.4 +- Add option to run single file mode from CLI + ### 0.5.3 - Add option to sort json arrays (including deep sorting) - Make single file comparison function to public api diff --git a/src/main.rs b/src/main.rs index 1df5139..7934cba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use anyhow::anyhow; use clap::Parser; -use havocompare::{compare_folders, get_schema, validate_config}; -use std::path::Path; +use havocompare::{compare_files, compare_folders, get_schema, validate_config, ComparisonMode}; +use std::path::{Path, PathBuf}; use tracing::{info, Level}; use tracing_subscriber::FmtSubscriber; @@ -24,6 +24,15 @@ enum Commands { #[arg(short, long)] open: bool, }, + /// Compare two files given a config-string that contains a json-serialized config + FileCompare { + /// nominal file + nominal: PathBuf, + /// actual file + actual: PathBuf, + /// compare_configuration in json + config: String, + }, /// Export the JsonSchema for the config files Schema, @@ -85,6 +94,22 @@ fn main() -> Result<(), vg_errortools::MainError> { Err(anyhow!("Comparison failed!").into()) } } + Commands::FileCompare { + nominal, + actual, + config, + } => { + use anyhow::Context; + let config: ComparisonMode = + serde_json::from_str(&config).context("Couldn't deserialize the config string")?; + let result = compare_files(nominal, actual, &config); + info!("Diff results: {result:#?}"); + if result.is_error { + Err(anyhow!("Comparison failed!").into()) + } else { + Ok(()) + } + } Commands::Validate { compare_config } => { if validate_config(compare_config) { Ok(())