stamtools/
validate.rs

1use stam::AnnotationStore;
2
3pub fn validate(
4    store: &AnnotationStore,
5    verbose: bool,
6    allow_incomplete: bool,
7) -> Result<(), String> {
8    let result = store.validate_text(!verbose);
9    let valid = if allow_incomplete {
10        result.is_ok_maybe_incomplete()
11    } else {
12        result.is_ok()
13    };
14    if valid {
15        if verbose {
16            eprintln!("Succesfully validated {} annotations", result.valid());
17        }
18        Ok(())
19    } else {
20        Err(format!(
21            "Failed to validate {} annotations, {} missing. {}",
22            result.invalid(),
23            result.missing(),
24            if result.missing() > 0 {
25                "Did you generate validation information? (run: stam validate --make)"
26            } else {
27                ""
28            }
29        ))
30    }
31}