Skip to content

Commit bfca2c0

Browse files
committed
clean up
1 parent 191dc83 commit bfca2c0

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

README.md

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
11
# Quiet
22

3-
When refactoring or working in some intermediate state, Cargo can end up spamming you with a lot of errors or warnings
4-
that you don't really care about. It would be nice to filter out these messages until you actually care about them.
3+
When refactoring or working in some intermediate state, Cargo can end up spamming you with a lot of errors or warnings that you don't really care about. It would be nice to filter out these messages until you actually care about them.
54

6-
Quiet lets you do this by only showing the number of errors you want. Quiet can also limit errors to only a file you
7-
specify.
5+
Quiet lets you do this by only showing the number of errors you want. Quiet can also limit errors to only a file you specify.
86

97

108
## Usage
119

1210
```
13-
quiet 0.1.11
14-
1511
Reduce Cargo's compiler information output
1612
17-
Usage: quiet [OPTIONS] --errors <ERRORS>
13+
Usage: quiet [OPTIONS] --items <ITEMS>
1814
1915
Options:
20-
--errors <ERRORS> The number of errors and/or warnings to display
16+
--items <ITEMS> The number of items to show. This includes errors and warnings to display. By default only errors are shown. Use --show-warnings to include warnings. Values range from 0 to 255
2117
--show-warnings Flag to include warnings in the output
22-
--file-filter <FILE_FILTER> The file (if any) to filter on Example: --file-filter main.rs
18+
--file-filter <FILE_FILTER> The file (if any) to filter on. Example: --file-filter main.rs
2319
-h, --help Print help information
2420
-V, --version Print version information
25-
2621
```
2722

2823
Cargo output should be passed to Quiet through the following format:
2924

25+
3026
```
31-
cargo check -q --message-format json-diagnostic-rendered-ansi
27+
cargo check -q --message-format json-diagnostic-rendered-ansi 2>&1
3228
```
3329

3430
For example to show only a single error for a project, run the following from your project directory:
3531

3632
```
37-
cargo check -q --message-format json-diagnostic-rendered-ansi | quiet --errors 1
33+
cargo check -q --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1
3834
```
3935

4036
You can also use it while running tests:
4137

4238
```
43-
cargo test -q --message-format json-diagnostic-rendered-ansi | quiet --errors 1
39+
cargo test --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1
4440
```
4541

4642
You can use it with `cargo watch` as:
4743

4844
```
49-
cargo watch -x 'test -q --message-format json-diagnostic-rendered-ansi | quiet --errors 1'
45+
cargo watch -x 'test --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1'
5046
```
5147

48+
Also look at the [qcompile](https://github.com/ssanj/quiet/blob/main/qcompile), [qcompile-test](https://github.com/ssanj/quiet/blob/main/qcompile-test) and [qrun-test](https://github.com/ssanj/quiet/blob/main/qrun-test) sample scripts in this repository.
49+
5250
## Building
5351

5452
Build Quiet with:

qcompile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
cargo watch -x 'check -q --message-format json-diagnostic-rendered-ansi | quiet --items 1'
3+
cargo watch -x 'check -q --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1'

qcompile-test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
cargo watch -x 'test --no-run -q --message-format json-diagnostic-rendered-ansi | quiet --items 1'
3+
cargo watch -x 'test --no-run -q --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1'

qrun-test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

33
if [ -z "$1" ]; then
4-
cargo watch -x 'test -q --message-format json-diagnostic-rendered-ansi | quiet --items 1'
4+
cargo watch -x 'test --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1'
55
else
6-
cargo watch -x 'test '"$1"' -q --message-format json-diagnostic-rendered-ansi | quiet --items 1'
6+
cargo watch -x 'test '"$1"' --message-format json-diagnostic-rendered-ansi 2>&1 | quiet --items 1'
77
fi
88

99

src/main.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ enum OutputType<'a> {
105105
}
106106

107107
fn print_compiler_output(constrained_matches: Vec<CompilerMessage>, level_status: LevelStatus) {
108+
println!();
108109
constrained_matches
109110
.into_iter()
110111
.for_each(|compiler_message|{
@@ -278,7 +279,9 @@ fn decode_compiler_message(line: &str) -> serde_json::Result<CompilerMessage> {
278279

279280
// TODO: Refactor this spaghetti code
280281
fn updated_stdout_line(line: &str, test_results_buffer: &mut HashMap<&str, u32>) -> Option<String> {
281-
if line == "failures:" {
282+
if line.is_empty() {
283+
None
284+
} else if line == "failures:" {
282285
let dots = print_success_dots(test_results_buffer.get("success"));
283286
Some(print_failures_line(line, dots.as_deref()))
284287
} else if line.starts_with("test result: FAILED.") {
@@ -291,11 +294,14 @@ fn updated_stdout_line(line: &str, test_results_buffer: &mut HashMap<&str, u32>)
291294
let output = print_test_success(line, dots.as_deref());
292295
test_results_buffer.clear();
293296
Some(output)
294-
} else if !line.is_empty() && line.split_inclusive(".").count() == line.len() {
297+
} else if line.split_inclusive(".").count() == line.len() {
295298
Some(print_test_run_dots(line))
296-
} else if line.contains(" Finished ") || line.contains(" Compiling ") { // TODO: Use regex. (dev|test|release)
299+
} else if line.trim().starts_with("Finished ") ||
300+
line.trim().starts_with("Compiling ") ||
301+
line.trim().starts_with("error: ") ||
302+
line.trim().starts_with("warning: ") {
297303
None
298-
} else if line.contains(" Running ") {
304+
} else if line.trim().starts_with("Running ") {
299305
Some(print_test_name(line))
300306
} else if line.ends_with("... ok") {
301307
// TODO: Move to a function
@@ -308,8 +314,6 @@ fn updated_stdout_line(line: &str, test_results_buffer: &mut HashMap<&str, u32>)
308314
None
309315
} else if line.ends_with("... FAILED") {
310316
Some(print_failed_test_name(line))
311-
} else if line.is_empty() {
312-
None
313317
} else {
314318
Some(default_stdout_line(line))
315319
}
@@ -322,7 +326,7 @@ fn print_failed_test_name(line: &str) -> String {
322326

323327

324328
fn print_test_name(line: &str) -> String {
325-
s!("\n{}", Yellow.paint(line.trim()))
329+
s!("\n{}", Yellow.paint(line.trim().strip_prefix("Running ").unwrap_or(line)))
326330
}
327331

328332

0 commit comments

Comments
 (0)