Skip to content

Commit ff0fff1

Browse files
committed
ref: correct fmt
1 parent 72391b2 commit ff0fff1

File tree

11 files changed

+150
-145
lines changed

11 files changed

+150
-145
lines changed

cli/src/analyser/diagnostics.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::formatter::{error, warning};
2+
use code0_definition_reader::reader::Meta;
23
use std::cmp::PartialEq;
34
use std::path::Path;
45
use std::process::exit;
5-
use code0_definition_reader::reader::Meta;
66

77
#[derive(Default)]
88
pub struct Reporter {
@@ -125,11 +125,7 @@ impl DiagnosticKind {
125125
}
126126

127127
impl Diagnose {
128-
pub fn new(
129-
definition_name: String,
130-
definition: Meta,
131-
kind: DiagnosticKind,
132-
) -> Self {
128+
pub fn new(definition_name: String, definition: Meta, kind: DiagnosticKind) -> Self {
133129
Self {
134130
definition_name,
135131
definition,

cli/src/analyser/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ impl Analyser {
5959
match definition.r#type {
6060
MetaType::FlowType => {
6161
current_index += 1;
62-
match serde_json::from_str::<FlowType>(
63-
definition.definition_string.as_str(),
64-
) {
62+
match serde_json::from_str::<FlowType>(definition.definition_string.as_str()) {
6563
Ok(flow_type) => collected_flow_types.push(AnalysableFlowType {
6664
original_definition: definition.clone(),
6765
flow_type,
@@ -755,7 +753,6 @@ impl Analyser {
755753
}
756754

757755
pub fn report(&mut self, will_exit: bool) {
758-
759756
for data_type in self.data_types.clone() {
760757
self.analyse_data_type(data_type.clone());
761758
}

cli/src/command/definition.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::formatter::{info, success};
12
use code0_definition_reader::parser::Parser;
23
use colored::Colorize;
3-
use crate::formatter::{info, success};
44

55
pub fn search_definition(name: String, path: Option<String>) {
66
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
@@ -35,11 +35,7 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
3535
let mut index = 0;
3636
for line in json.lines() {
3737
index += 1;
38-
println!(
39-
"{} {}",
40-
format!("{index}:"),
41-
line.bright_cyan()
42-
);
38+
println!("{} {}", format!("{index}:"), line.bright_cyan());
4339
}
4440
}
4541
Err(_) => println!("{}", "Error serializing FlowType".red()),
@@ -61,11 +57,7 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
6157
let mut index = 0;
6258
for line in json.lines() {
6359
index += 1;
64-
println!(
65-
"{} {}",
66-
format!("{index}:"),
67-
line.bright_cyan()
68-
);
60+
println!("{} {}", format!("{index}:"), line.bright_cyan());
6961
}
7062
}
7163
Err(_) => println!("{}", "Error serializing DataType".red()),
@@ -87,11 +79,7 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
8779
let mut index = 0;
8880
for line in json.lines() {
8981
index += 1;
90-
println!(
91-
"{} {}",
92-
format!("{index}:"),
93-
line.bright_cyan()
94-
);
82+
println!("{} {}", format!("{index}:"), line.bright_cyan());
9583
}
9684
}
9785
Err(_) => println!("{}", "Error serializing RuntimeFunction".red()),
@@ -101,7 +89,10 @@ fn search_and_display_definitions(search_name: &str, parser: &Parser) {
10189
}
10290

10391
if !found_any {
104-
println!("{}", format!("\n{}: {}", "error".red(), "Found no matching definition(s)"));
92+
println!(
93+
"{}",
94+
format!("\n{}: {}", "error".red(), "Found no matching definition(s)")
95+
);
10596
} else {
10697
success(format!("Found {total_matches} matching definition(s)"))
10798
}

cli/src/command/download.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
use crate::formatter::{error_without_trace, info, success};
12
use bytes::Bytes;
2-
use colored::*;
33
use reqwest::header::{ACCEPT, USER_AGENT};
44
use serde::Deserialize;
55
use std::fs;
66
use std::fs::File;
77
use std::path::Path;
88
use zip::ZipArchive;
9-
use crate::formatter::{error_without_trace, info, success};
109

1110
#[derive(Deserialize, Debug)]
1211
struct Release {
@@ -28,9 +27,7 @@ pub async fn handle_download(tag: Option<String>, features: Option<Vec<String>>)
2827
// Download the definitions
2928
info("Starting download process...".to_string());
3029
let bytes = match download_definitions_as_bytes(tag).await {
31-
Some(bytes) => {
32-
bytes
33-
}
30+
Some(bytes) => bytes,
3431
None => {
3532
error_without_trace(String::from("Download failed."));
3633
return;
@@ -49,7 +46,10 @@ pub async fn handle_download(tag: Option<String>, features: Option<Vec<String>>)
4946
}
5047

5148
let path = Path::new(out_folder_path);
52-
success(format!("Download was successful. Definitions are now available: {}.", path.display()));
49+
success(format!(
50+
"Download was successful. Definitions are now available: {}.",
51+
path.display()
52+
));
5353
}
5454

5555
async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Bytes> {
@@ -100,11 +100,11 @@ async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Byt
100100
.into_iter()
101101
.find(|a| a.name == "definitions.zip")
102102
{
103-
Some(asset) => {
104-
asset
105-
}
103+
Some(asset) => asset,
106104
None => {
107-
panic!("Definition folder is not called `definitions.zip` and was not inside the asset folder of the GitHub release!");
105+
panic!(
106+
"Definition folder is not called `definitions.zip` and was not inside the asset folder of the GitHub release!"
107+
);
108108
}
109109
};
110110

@@ -127,7 +127,10 @@ async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Byt
127127
}
128128
}
129129
} else {
130-
error_without_trace(format!("Download failed with status: {}", response.status()));
130+
error_without_trace(format!(
131+
"Download failed with status: {}",
132+
response.status()
133+
));
131134
None
132135
}
133136
}
@@ -138,7 +141,6 @@ async fn download_definitions_as_bytes(tag: Option<String>) -> Option<bytes::Byt
138141
}
139142

140143
async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
141-
142144
if let Err(e) = fs::write(zip_path, &bytes) {
143145
panic!("Failed to write zip file: {e}")
144146
}
@@ -151,9 +153,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
151153
};
152154

153155
let mut archive = match ZipArchive::new(zip_file) {
154-
Ok(archive) => {
155-
archive
156-
}
156+
Ok(archive) => archive,
157157
Err(e) => {
158158
panic!("Failed to read zip archive: {e}");
159159
}
@@ -177,11 +177,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
177177

178178
if file.name().ends_with('/') {
179179
if let Err(e) = fs::create_dir_all(&out_path) {
180-
panic!(
181-
"Failed to create directory {}: {}",
182-
out_path.display(),
183-
e
184-
);
180+
panic!("Failed to create directory {}: {}", out_path.display(), e);
185181
}
186182
} else {
187183
if let Some(p) = out_path.parent() {
@@ -203,11 +199,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
203199
}
204200
}
205201
Err(e) => {
206-
panic!(
207-
"Failed to create file {}: {}",
208-
out_path.display(),
209-
e
210-
);
202+
panic!("Failed to create file {}: {}", out_path.display(), e);
211203
}
212204
}
213205
}
@@ -218,7 +210,7 @@ async fn convert_bytes_to_folder(bytes: Bytes, zip_path: &str) {
218210

219211
match fs::remove_file(zip_path) {
220212
Ok(_) => info("Temporary zip file removed".to_string()),
221-
Err(e) => error_without_trace(format!("Warning: Failed to remove temporary zip file: {e}"))
213+
Err(e) => error_without_trace(format!("Warning: Failed to remove temporary zip file: {e}")),
222214
}
223215
}
224216

@@ -227,12 +219,14 @@ async fn filter_features(selected_features: Vec<String>) {
227219

228220
match fs::read_dir(definitions_path) {
229221
Ok(entries) => {
230-
231222
for entry in entries {
232223
let directory = match entry {
233224
Ok(directory) => directory,
234225
Err(e) => {
235-
panic!("{}", format!("Warning: Failed to read directory entry: {e}"));
226+
panic!(
227+
"{}",
228+
format!("Warning: Failed to read directory entry: {e}")
229+
);
236230
}
237231
};
238232

@@ -249,9 +243,7 @@ async fn filter_features(selected_features: Vec<String>) {
249243
}
250244
}
251245
Err(e) => {
252-
error_without_trace(
253-
format!("Failed to read definitions directory: {e}")
254-
);
246+
error_without_trace(format!("Failed to read definitions directory: {e}"));
255247
}
256248
}
257249
}

cli/src/command/feature.rs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use crate::table::{feature_table, summary_table};
2-
use code0_definition_reader::parser::{Feature, Parser};
31
use crate::analyser::Analyser;
42
use crate::formatter::{success, success_table};
3+
use crate::table::{feature_table, summary_table};
4+
use code0_definition_reader::parser::{Feature, Parser};
55

66
pub fn search_feature(name: Option<String>, path: Option<String>) {
77
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
@@ -17,42 +17,66 @@ pub fn search_feature(name: Option<String>, path: Option<String>) {
1717
analyser.report(true);
1818

1919
let features = match name {
20-
None => {
21-
parser.features.clone()
22-
}
23-
Some(feature_name) => {
24-
parser.features.iter().filter(|f| f.name.to_lowercase() == feature_name.to_lowercase()).map(|f| f.clone()).collect::<Vec<Feature>>()
25-
}
20+
None => parser.features.clone(),
21+
Some(feature_name) => parser
22+
.features
23+
.iter()
24+
.filter(|f| f.name.to_lowercase() == feature_name.to_lowercase())
25+
.map(|f| f.clone())
26+
.collect::<Vec<Feature>>(),
2627
};
27-
28-
28+
2929
for feature in &features {
3030
let (flow_type_rows, data_type_rows, function_rows) = feature_table(feature);
3131

3232
if !flow_type_rows.is_empty() {
33-
success(format!("The feature (`{}`) detected {} flow_types.", feature.name, flow_type_rows.len()));
33+
success(format!(
34+
"The feature (`{}`) detected {} flow_types.",
35+
feature.name,
36+
flow_type_rows.len()
37+
));
3438
success_table(flow_type_rows)
3539
}
3640

3741
if !data_type_rows.is_empty() {
38-
success(format!("The feature (`{}`) detected {} data_types.", feature.name, data_type_rows.len()));
42+
success(format!(
43+
"The feature (`{}`) detected {} data_types.",
44+
feature.name,
45+
data_type_rows.len()
46+
));
3947
success_table(data_type_rows)
4048
}
4149

4250
if !function_rows.is_empty() {
43-
success(format!("The feature (`{}`) detected {} runtime_function_definition.", feature.name, function_rows.len()));
51+
success(format!(
52+
"The feature (`{}`) detected {} runtime_function_definition.",
53+
feature.name,
54+
function_rows.len()
55+
));
4456
success_table(function_rows)
4557
}
4658
}
4759

4860
let summary = summary_table(&features);
4961
success_table(summary);
5062

51-
success(
52-
format!("Defined a total of {} Features with {} FlowTypes {} DataTypes and {} Functions!",
53-
parser.features.iter().len(),
54-
parser.features.iter().map(|f| f.flow_types.len()).sum::<usize>(),
55-
parser.features.iter().map(|f| f.data_types.len()).sum::<usize>(),
56-
parser.features.iter().map(|f| f.runtime_functions.len()).sum::<usize>()
63+
success(format!(
64+
"Defined a total of {} Features with {} FlowTypes {} DataTypes and {} Functions!",
65+
parser.features.iter().len(),
66+
parser
67+
.features
68+
.iter()
69+
.map(|f| f.flow_types.len())
70+
.sum::<usize>(),
71+
parser
72+
.features
73+
.iter()
74+
.map(|f| f.data_types.len())
75+
.sum::<usize>(),
76+
parser
77+
.features
78+
.iter()
79+
.map(|f| f.runtime_functions.len())
80+
.sum::<usize>()
5781
))
5882
}

cli/src/command/report.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::analyser::Analyser;
2-
use crate::table::{summary_table};
3-
use code0_definition_reader::parser::Parser;
42
use crate::formatter::{success, success_table};
3+
use crate::table::summary_table;
4+
use code0_definition_reader::parser::Parser;
55

66
pub fn report_errors(path: Option<String>) {
77
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
@@ -19,11 +19,23 @@ pub fn report_errors(path: Option<String>) {
1919
let rows = summary_table(&parser.features);
2020
success_table(rows);
2121

22-
success(
23-
format!("Defined a total of {} Features with {} FlowTypes {} DataTypes and {} Functions!",
22+
success(format!(
23+
"Defined a total of {} Features with {} FlowTypes {} DataTypes and {} Functions!",
2424
parser.features.iter().len(),
25-
parser.features.iter().map(|f| f.flow_types.len()).sum::<usize>(),
26-
parser.features.iter().map(|f| f.data_types.len()).sum::<usize>(),
27-
parser.features.iter().map(|f| f.runtime_functions.len()).sum::<usize>()
25+
parser
26+
.features
27+
.iter()
28+
.map(|f| f.flow_types.len())
29+
.sum::<usize>(),
30+
parser
31+
.features
32+
.iter()
33+
.map(|f| f.data_types.len())
34+
.sum::<usize>(),
35+
parser
36+
.features
37+
.iter()
38+
.map(|f| f.runtime_functions.len())
39+
.sum::<usize>()
2840
))
2941
}

0 commit comments

Comments
 (0)