-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature.rs
More file actions
82 lines (72 loc) · 2.37 KB
/
Copy pathfeature.rs
File metadata and controls
82 lines (72 loc) · 2.37 KB
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
use crate::analyser::Analyser;
use crate::formatter::{success, success_table};
use crate::parser::{Feature, Parser};
use crate::table::{feature_table, summary_table};
pub fn search_feature(name: Option<String>, path: Option<String>) {
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
let parser = match Parser::from_path(dir_path.as_str()) {
Some(reader) => reader,
None => {
panic!("Error reading definitions");
}
};
let mut analyser = Analyser::new(dir_path.as_str());
analyser.report(true);
let features = match name {
None => parser.features.clone(),
Some(feature_name) => parser
.features
.iter()
.filter(|f| f.name.to_lowercase() == feature_name.to_lowercase())
.cloned()
.collect::<Vec<Feature>>(),
};
for feature in &features {
let (flow_type_rows, data_type_rows, function_rows) = feature_table(feature);
if !flow_type_rows.is_empty() {
success(format!(
"The feature (`{}`) detected {} flow_types.",
feature.name,
flow_type_rows.len()
));
success_table(flow_type_rows)
}
if !data_type_rows.is_empty() {
success(format!(
"The feature (`{}`) detected {} data_types.",
feature.name,
data_type_rows.len()
));
success_table(data_type_rows)
}
if !function_rows.is_empty() {
success(format!(
"The feature (`{}`) detected {} runtime_function_definition.",
feature.name,
function_rows.len()
));
success_table(function_rows)
}
}
let summary = summary_table(&features);
success_table(summary);
success(format!(
"Defined a total of {} Features with {} FlowTypes {} DataTypes and {} Functions!",
parser.features.iter().len(),
parser
.features
.iter()
.map(|f| f.flow_types.len())
.sum::<usize>(),
parser
.features
.iter()
.map(|f| f.data_types.len())
.sum::<usize>(),
parser
.features
.iter()
.map(|f| f.runtime_functions.len())
.sum::<usize>()
))
}