1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use std::error::Error;
use crate::{Context, CES, error::AcesError};
use super::{App, Command};
pub struct Validate {
glob_path: String,
do_abort: bool,
syntax_only: bool,
is_recursive: bool,
verbosity: u64,
}
impl Validate {
pub fn new_command(app: &App) -> Box<dyn Command> {
let glob_path = app.value_of("GLOB_PATH").unwrap_or_else(|| unreachable!()).to_owned();
let do_abort = app.is_present("abort");
let syntax_only = app.is_present("syntax");
let is_recursive = app.is_present("recursive");
let verbosity = app.occurrences_of("verbose").max(app.occurrences_of("log"));
Box::new(Self { glob_path, do_abort, syntax_only, is_recursive, verbosity })
}
}
impl Command for Validate {
fn name_of_log_file(&self) -> String {
"aces-validation.log".to_owned()
}
fn run(&self) -> Result<(), Box<dyn Error>> {
// FIXME
let ref glob_path = format!("{}/*.ces", self.glob_path);
let mut num_bad_files = 0;
let ctx = Context::new_as_handle();
if self.is_recursive {
// FIXME
}
match glob::glob(glob_path) {
Ok(path_list) => {
for entry in path_list {
match entry {
Ok(ref path) => {
if self.verbosity >= 1 {
info!("> {}", path.display());
}
let result = CES::from_file(ctx.clone(), path);
match result {
Ok(ces) => {
if self.verbosity >= 2 {
debug!("{:?}", ces);
}
if !self.syntax_only && !ces.is_coherent() {
let err = AcesError::CESIsIncoherent(
ces.get_name().unwrap_or("anonymous").to_owned(),
);
if self.do_abort {
warn!("Aborting on structural error");
return Err(Box::new(err))
} else {
error!(
"Structural error in file '{}'...\n\t{}",
path.display(),
err
);
num_bad_files += 1;
}
}
}
Err(err) => {
if self.do_abort {
warn!("Aborting on syntax error");
return Err(err)
} else {
error!(
"Syntax error in file '{}'...\n\t{}",
path.display(),
err
);
num_bad_files += 1;
}
}
}
}
Err(err) => {
error!("Bad entry in path list: {}", err);
}
}
}
if num_bad_files > 0 {
println!(
"... Done ({} bad file{}).",
num_bad_files,
if num_bad_files == 1 { "" } else { "s" },
);
} else {
println!("... Done (no bad files).");
}
if self.verbosity >= 3 {
if self.verbosity >= 4 {
trace!("{:?}", ctx.lock().unwrap());
} else {
trace!("{:?}", ctx.lock().unwrap().nodes);
}
}
Ok(())
}
Err(err) => panic!("Invalid glob pattern: {}", err),
}
}
}