Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.5.4 single file mode runnable from cli #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading