Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/uu/pr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ path = "src/pr.rs"
[dependencies]
clap = { workspace = true }
uucore = { workspace = true, features = ["entries"] }
quick-error = { workspace = true }
itertools = { workspace = true }
regex = { workspace = true }
chrono = { workspace = true }
thiserror.workspace = true
Comment thread
Qelxiros marked this conversation as resolved.
Outdated

[[bin]]
name = "pr"
Expand Down
52 changes: 18 additions & 34 deletions src/uu/pr/src/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
use chrono::{DateTime, Local};
use clap::{Arg, ArgAction, ArgMatches, Command};
use itertools::Itertools;
use quick_error::ResultExt;
use regex::Regex;
use std::fs::{File, metadata};
use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout};
#[cfg(unix)]
use std::os::unix::fs::FileTypeExt;
use thiserror::Error;

use quick_error::quick_error;
use uucore::display::Quotable;
use uucore::error::UResult;
use uucore::{format_usage, help_about, help_section, help_usage};
Expand Down Expand Up @@ -134,35 +133,20 @@ impl From<std::io::Error> for PrError {
}
}

quick_error! {
#[derive(Debug)]
enum PrError {
Input(err: std::io::Error, path: String) {
context(path: &'a str, err: std::io::Error) -> (err, path.to_owned())
display("pr: Reading from input {path} gave error")
source(err)
}

UnknownFiletype(path: String) {
display("pr: {path}: unknown filetype")
}

EncounteredErrors(msg: String) {
display("pr: {msg}")
}

IsDirectory(path: String) {
display("pr: {path}: Is a directory")
}

IsSocket(path: String) {
display("pr: cannot open {path}, Operation not supported on socket")
}

NotExists(path: String) {
display("pr: cannot open {path}, No such file or directory")
}
}
#[derive(Debug, Error)]
enum PrError {
#[error("pr: Reading from input {1} gave error")]
Input(std::io::Error, String),
#[error("pr: {0}: unknown filetype")]
UnknownFiletype(String),
#[error("pr: {0}")]
EncounteredErrors(String),
#[error("pr: {0}: Is a directory")]
IsDirectory(String),
#[error("pr: cannot open {0}, Operation not supported on socket")]
IsSocket(String),
#[error("pr: cannot open {0}, No such file or directory")]
NotExists(String),
}

pub fn uu_app() -> Command {
Expand Down Expand Up @@ -795,9 +779,9 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
#[cfg(unix)]
ft if ft.is_socket() => Err(PrError::IsSocket(path_string)),
ft if ft.is_dir() => Err(PrError::IsDirectory(path_string)),
ft if ft.is_file() || ft.is_symlink() => {
Ok(Box::new(File::open(path).context(path)?) as Box<dyn Read>)
}
ft if ft.is_file() || ft.is_symlink() => Ok(Box::new(
File::open(path).map_err(|e| PrError::Input(e, path.to_string()))?,
) as Box<dyn Read>),
_ => Err(PrError::UnknownFiletype(path_string)),
}
})
Expand Down