Skip to content

Commit a8cb7da

Browse files
committed
feat: added new definition types (RuntimeFlowTypes, Functions, ModuleConfigurationDefinition)
1 parent 7f8e167 commit a8cb7da

12 files changed

Lines changed: 598 additions & 318 deletions

File tree

crates/cli/src/analyser/core.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use crate::analyser::index_identifier::IdentifierIndex;
1+
use crate::{analyser::index_identifier::IdentifierIndex, reader::Meta};
22
use crate::diagnostics::diagnose::Diagnose;
33
use crate::diagnostics::kinds::DiagnosticKind;
44
use crate::diagnostics::reporter::Reporter;
5-
use crate::parser::Meta;
65
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition};
76

87
#[derive(Clone)]

crates/cli/src/analyser/loader.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::core::{AnalysableDataType, AnalysableFlowType, AnalysableFunction, Analyser};
2-
use crate::analyser::index_identifier::IdentifierIndex;
32
use crate::diagnostics::diagnose::Diagnose;
43
use crate::diagnostics::kinds::DiagnosticKind;
54
use crate::diagnostics::reporter::Reporter;
6-
use crate::parser::{MetaType, Parser, Reader};
5+
use crate::parser::Parser;
6+
use crate::reader::MetaType;
7+
use crate::{analyser::index_identifier::IdentifierIndex, reader::Reader};
78
use tucana::shared::{DefinitionDataType, FlowType, RuntimeFunctionDefinition};
89

910
pub fn load_from_path(path: &str) -> Analyser {
@@ -130,6 +131,9 @@ pub fn load_from_path(path: &str) -> Analyser {
130131
}
131132
}
132133
}
134+
MetaType::RuntimeFlowType => todo!(),
135+
MetaType::Function => todo!(),
136+
MetaType::Configs => todo!(),
133137
}
134138
}
135139
Analyser {

crates/cli/src/command/feature.rs

Lines changed: 0 additions & 82 deletions
This file was deleted.

crates/cli/src/command/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub mod download;
2-
pub mod feature;
2+
pub mod search_module;
33
pub mod push;
44
pub mod report;
55
pub mod search;

crates/cli/src/command/report.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use tucana::shared::Module;
2+
13
use crate::analyser::core::Analyser;
24
use crate::formatter::{success, success_table};
35
use crate::parser::Parser;
@@ -15,27 +17,32 @@ pub fn report_errors(path: Option<String>) {
1517

1618
let mut analyser = Analyser::new(dir_path.as_str());
1719
analyser.report(true, true);
20+
let mods: &Vec<Module> = &parser
21+
.modules
22+
.clone()
23+
.into_iter()
24+
.map(|x| x.into_module())
25+
.collect();
1826

19-
let rows = summary_table(&parser.features);
27+
let rows = summary_table(mods);
2028
success_table(rows);
2129

2230
success(format!(
23-
"Defined a total of {} Features with {} FlowTypes {} DataTypes and {} Functions!",
24-
parser.features.iter().len(),
25-
parser
26-
.features
27-
.iter()
28-
.map(|f| f.flow_types.len())
31+
"Defined a total of {} Modules with {} RuntimeFlowTypes, {} FlowTypes, {} DataTypes, {} RuntimeFunctions, {} Functions and {} Module Configs!",
32+
mods.iter().len(),
33+
mods.iter()
34+
.map(|f| f.runtime_flow_types.len())
35+
.sum::<usize>(),
36+
mods.iter().map(|f| f.flow_types.len()).sum::<usize>(),
37+
mods.iter()
38+
.map(|f| f.definition_data_types.len())
39+
.sum::<usize>(),
40+
mods.iter()
41+
.map(|f| f.runtime_function_definitions.len())
2942
.sum::<usize>(),
30-
parser
31-
.features
32-
.iter()
33-
.map(|f| f.data_types.len())
43+
mods.iter()
44+
.map(|f| f.function_definitions.len())
3445
.sum::<usize>(),
35-
parser
36-
.features
37-
.iter()
38-
.map(|f| f.runtime_functions.len())
39-
.sum::<usize>()
46+
mods.iter().map(|f| f.configurations.len()).sum::<usize>(),
4047
))
4148
}

crates/cli/src/command/search.rs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,29 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
2020
let mut total_matches = 0;
2121
info(format!("Searching for '{}'", search_name));
2222

23-
for feature in &parser.features {
23+
for feature in &parser.modules {
24+
// Search RuntimeFlowTypes
25+
for flow_type in &feature.runtime_flow_types {
26+
if flow_type.identifier == search_name {
27+
total_matches += 1;
28+
if !found_any {
29+
found_any = true;
30+
}
31+
32+
info(String::from("Found flow_type:\n"));
33+
match serde_json::to_string_pretty(flow_type) {
34+
Ok(json) => {
35+
let mut index = 0;
36+
for line in json.lines() {
37+
index += 1;
38+
println!("{}: {}", index, line.bright_cyan());
39+
}
40+
}
41+
Err(_) => println!("{}", "Error serializing FlowType".red()),
42+
}
43+
}
44+
}
45+
2446
// Search FlowTypes
2547
for flow_type in &feature.flow_types {
2648
if flow_type.identifier == search_name {
@@ -86,6 +108,50 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
86108
}
87109
}
88110
}
111+
112+
// Search RuntimeFunctions
113+
for runtime_func in &feature.functions {
114+
if runtime_func.runtime_name == search_name {
115+
total_matches += 1;
116+
if !found_any {
117+
found_any = true;
118+
}
119+
120+
info(String::from("Found runtime_function_definition:\n"));
121+
match serde_json::to_string_pretty(runtime_func) {
122+
Ok(json) => {
123+
let mut index = 0;
124+
for line in json.lines() {
125+
index += 1;
126+
println!("{}: {}", index, line.bright_cyan());
127+
}
128+
}
129+
Err(_) => println!("{}", "Error serializing RuntimeFunction".red()),
130+
}
131+
}
132+
}
133+
134+
// Search Module Configurations
135+
for runtime_func in &feature.module_configs {
136+
if runtime_func.identifier == search_name {
137+
total_matches += 1;
138+
if !found_any {
139+
found_any = true;
140+
}
141+
142+
info(String::from("Found runtime_function_definition:\n"));
143+
match serde_json::to_string_pretty(runtime_func) {
144+
Ok(json) => {
145+
let mut index = 0;
146+
for line in json.lines() {
147+
index += 1;
148+
println!("{}: {}", index, line.bright_cyan());
149+
}
150+
}
151+
Err(_) => println!("{}", "Error serializing RuntimeFunction".red()),
152+
}
153+
}
154+
}
89155
}
90156

91157
if !found_any {
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
use tucana::shared::Module;
2+
3+
use crate::analyser::core::Analyser;
4+
use crate::formatter::{success, success_table};
5+
use crate::parser::{DefinitionModule, Parser};
6+
use crate::table::{module_table, summary_table};
7+
8+
pub fn search_module(name: Option<String>, path: Option<String>) {
9+
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
10+
11+
let parser = match Parser::from_path(dir_path.as_str()) {
12+
Some(reader) => reader,
13+
None => {
14+
panic!("Error reading definitions");
15+
}
16+
};
17+
18+
let mut analyser = Analyser::new(dir_path.as_str());
19+
analyser.report(true, true);
20+
21+
let modules = match name {
22+
None => parser.modules.clone(),
23+
Some(feature_name) => parser
24+
.modules
25+
.iter()
26+
.filter(|m| m.config.identifier.to_lowercase() == feature_name.to_lowercase())
27+
.cloned()
28+
.collect::<Vec<DefinitionModule>>(),
29+
};
30+
31+
for module in &modules {
32+
let (
33+
runtime_flow_type_rows,
34+
flow_type_rows,
35+
data_type_rows,
36+
runtime_function_rows,
37+
function_rows,
38+
configuration_rows,
39+
) = module_table(&module.clone().into_module());
40+
41+
if !runtime_flow_type_rows.is_empty() {
42+
success(format!(
43+
"The module (`{}`) detected {} runtime_flow_types.",
44+
module.config.identifier,
45+
runtime_flow_type_rows.len()
46+
));
47+
success_table(runtime_flow_type_rows)
48+
}
49+
50+
if !flow_type_rows.is_empty() {
51+
success(format!(
52+
"The module (`{}`) detected {} flow_types.",
53+
module.config.identifier,
54+
flow_type_rows.len()
55+
));
56+
success_table(flow_type_rows)
57+
}
58+
59+
if !data_type_rows.is_empty() {
60+
success(format!(
61+
"The module (`{}`) detected {} data_types.",
62+
module.config.identifier,
63+
data_type_rows.len()
64+
));
65+
success_table(data_type_rows)
66+
}
67+
68+
if !runtime_function_rows.is_empty() {
69+
success(format!(
70+
"The module (`{}`) detected {} runtime_function_definition.",
71+
module.config.identifier,
72+
runtime_function_rows.len()
73+
));
74+
success_table(runtime_function_rows)
75+
}
76+
77+
if !function_rows.is_empty() {
78+
success(format!(
79+
"The module (`{}`) detected {} function_definition.",
80+
module.config.identifier,
81+
function_rows.len()
82+
));
83+
success_table(function_rows)
84+
}
85+
86+
if !configuration_rows.is_empty() {
87+
success(format!(
88+
"The module (`{}`) detected {} module_configurations.",
89+
module.config.identifier,
90+
configuration_rows.len()
91+
));
92+
success_table(configuration_rows)
93+
}
94+
}
95+
96+
let mods: &Vec<Module> = &parser
97+
.modules
98+
.clone()
99+
.into_iter()
100+
.map(|x| x.into_module())
101+
.collect();
102+
103+
let summary = summary_table(&mods);
104+
success_table(summary);
105+
106+
success(format!(
107+
"Defined a total of {} Modules with {} RuntimeFlowTypes, {} FlowTypes, {} DataTypes, {} RuntimeFunctions, {} Functions and {} Module Configs!",
108+
mods.iter().len(),
109+
mods.iter()
110+
.map(|f| f.runtime_flow_types.len())
111+
.sum::<usize>(),
112+
mods.iter().map(|f| f.flow_types.len()).sum::<usize>(),
113+
mods.iter()
114+
.map(|f| f.definition_data_types.len())
115+
.sum::<usize>(),
116+
mods.iter()
117+
.map(|f| f.runtime_function_definitions.len())
118+
.sum::<usize>(),
119+
mods.iter()
120+
.map(|f| f.function_definitions.len())
121+
.sum::<usize>(),
122+
mods.iter().map(|f| f.configurations.len()).sum::<usize>(),
123+
))
124+
}

crates/cli/src/diagnostics/diagnose.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::diagnostics::kinds::DiagnosticKind;
22
use crate::diagnostics::kinds::DiagnosticKind::*;
33
use crate::diagnostics::severity::Severity;
44
use crate::formatter::{error, warning};
5-
use crate::parser::Meta;
5+
use crate::reader::Meta;
66
use std::path::Path;
77

88
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)