Skip to content

Commit fa774f6

Browse files
Merge pull request #210 from code0-tech/196-update-cli
Update CLI
2 parents 79245bb + 16c7412 commit fa774f6

File tree

12 files changed

+117
-18
lines changed

12 files changed

+117
-18
lines changed

crates/cli/src/analyser/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Analyser {
3939
super::loader::load_from_path(path)
4040
}
4141

42-
pub fn report(&mut self, will_exit: bool) {
42+
pub fn report(&mut self, will_exit: bool, with_warning: bool) {
4343
// Run analysis passes
4444
for dt in self.data_types.clone() {
4545
self.analyse_data_type(&dt);
@@ -50,7 +50,7 @@ impl Analyser {
5050
for f in self.functions.clone() {
5151
self.analyse_runtime_function(&f);
5252
}
53-
self.reporter.print(will_exit);
53+
self.reporter.print(will_exit, true, with_warning);
5454
}
5555

5656
pub fn data_type_identifier_exists(&self, identifier: &str, except_id: Option<i16>) -> bool {

crates/cli/src/analyser/data_type.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ impl Analyser {
2626
));
2727
}
2828

29+
if dt.alias.is_empty() {
30+
self.reporter.add(Diagnose::new(
31+
dt.identifier.clone(),
32+
adt.original_definition.clone(),
33+
DiagnosticKind::MissingTranslation {
34+
translation_field: "alias".into(),
35+
},
36+
));
37+
}
38+
39+
if dt.display_message.is_empty() {
40+
self.reporter.add(Diagnose::new(
41+
dt.identifier.clone(),
42+
adt.original_definition.clone(),
43+
DiagnosticKind::MissingTranslation {
44+
translation_field: "displayMessage".into(),
45+
},
46+
));
47+
}
2948
let mut detected: Vec<String> = vec![];
3049
for optional_rule in &dt.rules {
3150
if let Some(config) = &optional_rule.config {

crates/cli/src/analyser/flow_type.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ impl Analyser {
88
let name = flow.identifier.clone();
99
let original = aft.original_definition.clone();
1010

11+
if flow.display_icon.is_empty() {
12+
self.reporter.add(Diagnose::new(
13+
name.clone(),
14+
original.clone(),
15+
DiagnosticKind::NullField {
16+
field_name: "displayIcon".into(),
17+
},
18+
))
19+
}
20+
if flow.alias.is_empty() {
21+
self.reporter.add(Diagnose::new(
22+
name.clone(),
23+
original.clone(),
24+
DiagnosticKind::MissingTranslation {
25+
translation_field: "alias".into(),
26+
},
27+
));
28+
}
29+
30+
if flow.display_message.is_empty() {
31+
self.reporter.add(Diagnose::new(
32+
name.clone(),
33+
original.clone(),
34+
DiagnosticKind::MissingTranslation {
35+
translation_field: "displayMessage".into(),
36+
},
37+
));
38+
}
39+
1140
if flow.name.is_empty() {
1241
self.reporter.add(Diagnose::new(
1342
name.clone(),

crates/cli/src/analyser/function.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ impl Analyser {
1010
let function = &af.function;
1111
let original = af.original_definition.clone();
1212

13+
if function.display_icon.is_empty() {
14+
self.reporter.add(Diagnose::new(
15+
name.clone(),
16+
original.clone(),
17+
DiagnosticKind::NullField {
18+
field_name: "displayIcon".into(),
19+
},
20+
))
21+
}
22+
23+
if function.alias.is_empty() {
24+
self.reporter.add(Diagnose::new(
25+
name.clone(),
26+
original.clone(),
27+
DiagnosticKind::MissingTranslation {
28+
translation_field: "alias".into(),
29+
},
30+
));
31+
}
32+
33+
if function.display_message.is_empty() {
34+
self.reporter.add(Diagnose::new(
35+
name.clone(),
36+
original.clone(),
37+
DiagnosticKind::MissingTranslation {
38+
translation_field: "displayMessage".into(),
39+
},
40+
));
41+
}
42+
1343
if function.name.is_empty() {
1444
self.reporter.add(Diagnose::new(
1545
name.clone(),

crates/cli/src/command/feature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn search_feature(name: Option<String>, path: Option<String>) {
1414
};
1515

1616
let mut analyser = Analyser::new(dir_path.as_str());
17-
analyser.report(true);
17+
analyser.report(true, true);
1818

1919
let features = match name {
2020
None => parser.features.clone(),

crates/cli/src/command/push/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub async fn push(token: String, url: String, path: Option<String>) {
2020
info(String::from("Press Ctrl+C to stop watching..."));
2121

2222
{
23-
Analyser::new(dir_path.as_str()).report(false);
23+
Analyser::new(dir_path.as_str()).report(false, true);
2424
}
2525

2626
// Set up file watcher
@@ -82,7 +82,7 @@ pub async fn push(token: String, url: String, path: Option<String>) {
8282
.await;
8383
}
8484

85-
analyzer.report(false);
85+
analyzer.report(false, true);
8686

8787
last_run = Instant::now();
8888
}
@@ -126,7 +126,7 @@ pub async fn push(token: String, url: String, path: Option<String>) {
126126
.await;
127127
}
128128

129-
analyzer.report(false);
129+
analyzer.report(false, true);
130130
last_run = Instant::now();
131131
}
132132
}

crates/cli/src/command/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn report_errors(path: Option<String>) {
1414
};
1515

1616
let mut analyser = Analyser::new(dir_path.as_str());
17-
analyser.report(true);
17+
analyser.report(true, true);
1818

1919
let rows = summary_table(&parser.features);
2020
success_table(rows);

crates/cli/src/command/watch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use notify::{EventKind, RecursiveMode, Watcher, recommended_watcher};
55
use std::sync::mpsc::channel;
66
use std::time::{Duration, Instant};
77

8-
pub async fn watch_for_changes(path: Option<String>) {
8+
pub async fn watch_for_changes(path: Option<String>, with_warning: bool) {
99
let dir_path = path.unwrap_or_else(|| "./definitions".to_string());
1010

1111
info(format!("Watching directory: {dir_path}"));
1212
info(String::from("Press Ctrl+C to stop watching..."));
1313

1414
{
15-
Analyser::new(dir_path.as_str()).report(false);
15+
Analyser::new(dir_path.as_str()).report(false, with_warning);
1616
}
1717

1818
// Set up file watcher
@@ -35,7 +35,7 @@ pub async fn watch_for_changes(path: Option<String>) {
3535
"\n\n\n--------------------------------------------------------------------------\n\n",
3636
));
3737
info(String::from("Change detected! Regenerating report..."));
38-
Analyser::new(dir_path.as_str()).report(false);
38+
Analyser::new(dir_path.as_str()).report(false, with_warning);
3939
last_run = Instant::now();
4040
}
4141
}
@@ -45,7 +45,7 @@ pub async fn watch_for_changes(path: Option<String>) {
4545
"\n\n\n--------------------------------------------------------------------------\n\n",
4646
));
4747
info(String::from("Change detected! Regenerating report..."));
48-
Analyser::new(dir_path.as_str()).report(false);
48+
Analyser::new(dir_path.as_str()).report(false, with_warning);
4949
last_run = Instant::now();
5050
}
5151
}

crates/cli/src/diagnostics/diagnose.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ impl Diagnose {
111111
),
112112
&path,
113113
),
114+
MissingTranslation { translation_field } => error(
115+
format!(
116+
"`{}` has an required empty field (`{}`) of translations!",
117+
self.definition_name, translation_field
118+
),
119+
&path,
120+
),
114121
}
115122
}
116123

crates/cli/src/diagnostics/kinds.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub enum DiagnosticKind {
1515
UnusedGenericKey { key: String },
1616
UndefinedGenericKey { key: String },
1717
UndefinedTranslation { translation_field: String },
18+
MissingTranslation { translation_field: String },
1819
}
1920

2021
impl DiagnosticKind {
@@ -32,7 +33,8 @@ impl DiagnosticKind {
3233
| NullField { .. }
3334
| ForbiddenVariant
3435
| UnusedGenericKey { .. }
35-
| UndefinedGenericKey { .. } => Severity::Error,
36+
| UndefinedGenericKey { .. }
37+
| MissingTranslation { .. } => Severity::Error,
3638
UndefinedTranslation { .. } => Severity::Warning,
3739
}
3840
}

0 commit comments

Comments
 (0)