|
| 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 | +} |
0 commit comments