Skip to content

Commit

Permalink
Add CLI to run in single-file-mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRega committed Feb 22, 2024
1 parent 5a35c55 commit 3edb046
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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,
} => {
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(())
Expand Down

0 comments on commit 3edb046

Please sign in to comment.