Skip to content

Commit

Permalink
Merge pull request #48 from ChrisRega/0.5.4-single-file-runnable-cli
Browse files Browse the repository at this point in the history
0.5.4 single file mode runnable from cli
  • Loading branch information
rohdealx authored Feb 27, 2024
2 parents 750f260 + e1e33c2 commit acd814e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 27 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit acd814e

Please sign in to comment.