-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefinition.rs
More file actions
122 lines (111 loc) · 4.01 KB
/
Copy pathdefinition.rs
File metadata and controls
122 lines (111 loc) · 4.01 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
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
120
121
122
use code0_definition_reader::parser::Parser;
use colored::Colorize;
pub fn search_definition(name: 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");
}
};
search_and_display_definitions(&name, &parser);
}
fn search_and_display_definitions(search_name: &str, parser: &Parser) {
let mut found_any = false;
let mut total_matches = 0;
println!(
"{}",
format!("Searching for definitions matching: '{search_name}'")
.bright_yellow()
.bold()
);
println!("{}", "─".repeat(60).dimmed());
for feature in &parser.features {
// Search FlowTypes
for flow_type in &feature.flow_types {
if flow_type.identifier == search_name {
total_matches += 1;
if !found_any {
found_any = true;
}
println!("\n{}", "FlowType".bright_cyan().bold());
match serde_json::to_string_pretty(flow_type) {
Ok(json) => {
let mut index = 0;
for line in json.lines() {
index += 1;
println!(
"{} {}",
format!("{index}:").bright_blue(),
line.bright_green()
);
}
}
Err(_) => println!("{}", "Error serializing FlowType".red()),
}
}
}
// Search DataTypes
for data_type in &feature.data_types {
if data_type.identifier == search_name {
total_matches += 1;
if !found_any {
found_any = true;
}
println!("\n{}", "DataType".bright_cyan().bold());
match serde_json::to_string_pretty(data_type) {
Ok(json) => {
let mut index = 0;
for line in json.lines() {
index += 1;
println!(
"{} {}",
format!("{index}:").bright_blue(),
line.bright_green()
);
}
}
Err(_) => println!("{}", "Error serializing DataType".red()),
}
}
}
// Search RuntimeFunctions
for runtime_func in &feature.runtime_functions {
if runtime_func.runtime_name == search_name {
total_matches += 1;
if !found_any {
found_any = true;
}
println!("\n{}", "RuntimeFunction".bright_cyan().bold());
match serde_json::to_string_pretty(runtime_func) {
Ok(json) => {
let mut index = 0;
for line in json.lines() {
index += 1;
println!(
"{} {}",
format!("{index}:").bright_blue(),
line.bright_green()
);
}
}
Err(_) => println!("{}", "Error serializing RuntimeFunction".red()),
}
}
}
}
if !found_any {
println!(
"\n{}",
format!("No definitions found matching '{search_name}'")
.red()
.bold()
);
} else {
println!("\n{}", "─".repeat(60).dimmed());
println!(
"{}",
format!("Found {total_matches} matching definition(s)").bright_yellow()
);
}
}