Skip to content

Commit dcbc67e

Browse files
committed
feat: added ignore warnings to watch command
1 parent 79245bb commit dcbc67e

7 files changed

Lines changed: 26 additions & 17 deletions

File tree

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/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/reporter.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ impl Reporter {
2828
self.diagnostics.is_empty()
2929
}
3030

31-
pub fn print(&self, will_exit: bool) {
32-
for d in self.errors() {
33-
println!("{}", d.print());
31+
pub fn print(&self, will_exit: bool, print_errors: bool, print_warning: bool) {
32+
if print_warning {
33+
for d in self.warnings() {
34+
println!("{}", d.print());
35+
}
3436
}
35-
for d in self.warnings() {
36-
println!("{}", d.print());
37+
38+
if print_errors {
39+
for d in self.errors() {
40+
println!("{}", d.print());
41+
}
3742
}
43+
3844
if self
3945
.diagnostics
4046
.iter()

crates/cli/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ enum Commands {
4949
/// Optional path to root directory of all definitions.
5050
#[arg(short, long)]
5151
path: Option<String>,
52+
/// Should ignore warnings, true on default
53+
#[arg(short, long, default_value_t = false)]
54+
ignore_warnings: bool,
5255
},
5356
Push {
5457
/// Runtime Token for Sagittarius.
@@ -80,7 +83,7 @@ async fn main() {
8083
Commands::Download { tag, features } => {
8184
command::download::handle_download(tag, features).await
8285
}
83-
Commands::Watch { path } => command::watch::watch_for_changes(path).await,
86+
Commands::Watch { path, ignore_warnings } => command::watch::watch_for_changes(path, !ignore_warnings).await,
8487
Commands::Push { token, url, path } => command::push::push(token, url, path).await,
8588
}
8689
}

0 commit comments

Comments
 (0)