1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2026-01-15 17:51:07 +00:00

more handle errors with multiple files (#4997)

* more handle errors with multiple files

* tests/more test refactor and new case

* tests/more new cases

* more: use show! and change exitstatus and adjust tests to new exitvalue

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
Ludmuterol 2024-02-04 16:32:14 +01:00 committed by GitHub
parent 40694c5e75
commit 96d96e7de3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 11 deletions

View file

@ -25,8 +25,8 @@ use crossterm::{
use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError, UUsageError};
use uucore::{display::Quotable, show};
use uucore::{format_usage, help_about, help_usage};
const ABOUT: &str = help_about!("more.md");
@ -113,25 +113,31 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let file = Path::new(file);
if file.is_dir() {
terminal::disable_raw_mode().unwrap();
return Err(UUsageError::new(
1,
show!(UUsageError::new(
0,
format!("{} is a directory.", file.quote()),
));
terminal::enable_raw_mode().unwrap();
continue;
}
if !file.exists() {
terminal::disable_raw_mode().unwrap();
return Err(USimpleError::new(
1,
show!(USimpleError::new(
0,
format!("cannot open {}: No such file or directory", file.quote()),
));
terminal::enable_raw_mode().unwrap();
continue;
}
let opened_file = match File::open(file) {
Err(why) => {
terminal::disable_raw_mode().unwrap();
return Err(USimpleError::new(
1,
show!(USimpleError::new(
0,
format!("cannot open {}: {}", file.quote(), why.kind()),
));
terminal::enable_raw_mode().unwrap();
continue;
}
Ok(opened_file) => opened_file,
};