hkxc/args/
verify.rs
1use crate::args::progress_handler::CliProgressHandler;
2use serde_hkx_features::{
3 error::Result,
4 verify::{verify_dir, verify_file},
5};
6use std::path::{Path, PathBuf};
7
8pub const EXAMPLES: &str = color_print::cstr!(
10 r#"In case of error, dir and file behave differently
11 - dir: All error paths are displayed
12 - file: Error path + diff displayed
13
14<blue><bold><underline>Examples</underline></bold></blue>
15- <blue!>Test the reproducibility of hkx</blue!>
16 <cyan!>hkxc verify</cyan!> ./defaultmale.hkx
17
18- <blue!>Test the reproducibility of hkx files</blue!>
19 <cyan!>./hkxc verify</cyan!> ./input --log-level info --log-file "./verify_inputs.log"
20"#
21);
22
23#[derive(Debug, clap::Args)]
24#[clap(arg_required_else_help = true, after_long_help = EXAMPLES)]
25pub(crate) struct Args {
26 pub path: PathBuf,
28 #[clap(long)]
30 pub color: bool,
31}
32
33pub fn verify<P>(path: P, color: bool) -> Result<()>
34where
35 P: AsRef<Path>,
36{
37 let path = path.as_ref();
38
39 if path.is_file() {
40 println!("Verifying...");
41 verify_file(path, color).map(|_| {
42 color_print::cprintln!(
43 "<green>Complete hkx reproduction: {}</green>",
44 path.display()
45 );
46 })
47 } else {
48 verify_dir(path, CliProgressHandler::new())
49 }
50}
51
52#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[ignore = "need templates"]
58 #[test]
59 fn test_verify_dir() {
60 let input = "../../tests/input";
61 verify(input, false).unwrap_or_else(|err| panic!("{err}"));
62 }
63}