Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 901bc38

Browse files
committed
feat: Return 1 if no dirs are found
A better error code
1 parent 3cce61f commit 901bc38

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

src/main.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,21 @@ fn main() {
307307
indicator.stop();
308308

309309
let print_errors = config.get_print_errors(&options);
310-
print_any_errors(print_errors, walk_data.errors);
311-
312-
print_output(
313-
config,
314-
options,
315-
tree,
316-
walk_data.by_filecount,
317-
is_colors,
318-
terminal_width,
319-
)
310+
let final_errors = walk_data.errors.lock().unwrap();
311+
print_any_errors(print_errors, &final_errors);
312+
313+
if tree.children.is_empty() && !final_errors.file_not_found.is_empty() {
314+
std::process::exit(1)
315+
} else {
316+
print_output(
317+
config,
318+
options,
319+
tree,
320+
walk_data.by_filecount,
321+
is_colors,
322+
terminal_width,
323+
)
324+
}
320325
});
321326
}
322327

@@ -357,8 +362,7 @@ fn print_output(
357362
}
358363
}
359364

360-
fn print_any_errors(print_errors: bool, errors: Arc<Mutex<RuntimeErrors>>) {
361-
let final_errors = errors.lock().unwrap();
365+
fn print_any_errors(print_errors: bool, final_errors: &RuntimeErrors) {
362366
if !final_errors.file_not_found.is_empty() {
363367
let err = final_errors
364368
.file_not_found

tests/test_flags.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ pub fn test_ignore_all_in_file() {
107107
#[test]
108108
pub fn test_with_bad_param() {
109109
let mut cmd = Command::cargo_bin("dust").unwrap();
110-
let result = cmd.arg("bad_place").unwrap();
110+
cmd.arg("-P").arg("bad_place");
111+
let output_error = cmd.unwrap_err();
112+
let result = output_error.as_output().unwrap();
111113
let stderr = str::from_utf8(&result.stderr).unwrap();
112114
assert!(stderr.contains("No such file or directory"));
113115
}

0 commit comments

Comments
 (0)