1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

fixup! wc: return UResult from uumain() function

This commit is contained in:
Jeffrey Finkelstein 2022-01-02 19:40:22 -05:00
parent e060ac53f2
commit 9caf15c44f

View file

@ -25,7 +25,7 @@ use std::io::{self, Write};
use std::path::{Path, PathBuf};
use uucore::display::{Quotable, Quoted};
use uucore::error::{UIoError, UResult};
use uucore::error::{UResult, USimpleError};
/// The minimum character width for formatting counts when reading from stdin.
const MINIMUM_WIDTH: usize = 7;
@ -426,24 +426,33 @@ fn wc(inputs: Vec<Input>, settings: &Settings) -> UResult<()> {
let word_count = match word_count_from_input(input, settings) {
CountResult::Success(word_count) => word_count,
CountResult::Interrupted(word_count, error) => {
show!(uio_error!(error, "{}", input.path_display()));
show!(USimpleError::new(
1,
format!("{}: {}", input.path_display(), error)
));
word_count
}
CountResult::Failure(error) => {
show!(uio_error!(error, "{}", input.path_display()));
show!(USimpleError::new(
1,
format!("{}: {}", input.path_display(), error)
));
continue;
}
};
total_word_count += word_count;
let result = word_count.with_title(input.to_title());
if let Err(err) = print_stats(settings, &result, max_width) {
show!(uio_error!(
err,
"failed to print result for {}",
result
.title
.unwrap_or_else(|| "<stdin>".as_ref())
.maybe_quote(),
show!(USimpleError::new(
1,
format!(
"failed to print result for {}: {}",
result
.title
.unwrap_or_else(|| "<stdin>".as_ref())
.maybe_quote(),
err,
),
));
}
}
@ -451,7 +460,10 @@ fn wc(inputs: Vec<Input>, settings: &Settings) -> UResult<()> {
if num_inputs > 1 {
let total_result = total_word_count.with_title(Some("total".as_ref()));
if let Err(err) = print_stats(settings, &total_result, max_width) {
show!(uio_error!(err, "failed to print total"));
show!(USimpleError::new(
1,
format!("failed to print total: {}", err)
));
}
}