From 3edb046eef9362f958db04cdf5631b41acfcab48 Mon Sep 17 00:00:00 2001 From: Christopher Regali Date: Thu, 22 Feb 2024 23:33:34 +0100 Subject: [PATCH 1/3] Add CLI to run in single-file-mode. --- Cargo.toml | 1 + src/main.rs | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3fd8436..39b6af1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ 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/src/main.rs b/src/main.rs index 1df5139..2d525c9 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, + } => { + let config: ComparisonMode = serde_json::from_str(&config) + .map_err(|e| format!("Couldn't deserialize the config string: {e}")) + .unwrap(); + 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(()) From e52d50d0cebbe391c00b4e772bb3c172f44c7baa Mon Sep 17 00:00:00 2001 From: Christopher Regali Date: Thu, 22 Feb 2024 23:35:11 +0100 Subject: [PATCH 2/3] Bump version and add README.md --- Cargo.toml | 2 +- README.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 39b6af1..746e55c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ 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"] 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 From e1e33c29d3631e189f432317f4c50586a344bde9 Mon Sep 17 00:00:00 2001 From: Christopher Regali <60792386+ChrisRega@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:21:29 +0100 Subject: [PATCH 3/3] use anyhow context Co-authored-by: Alexander Rohde --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2d525c9..7934cba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,9 +99,9 @@ fn main() -> Result<(), vg_errortools::MainError> { actual, config, } => { - let config: ComparisonMode = serde_json::from_str(&config) - .map_err(|e| format!("Couldn't deserialize the config string: {e}")) - .unwrap(); + 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 {