mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
ptx: move to thiserror
This commit is contained in:
parent
aea23408fd
commit
4cb23dd840
3 changed files with 8 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3102,6 +3102,7 @@ version = "0.0.30"
|
|||
dependencies = [
|
||||
"clap",
|
||||
"regex",
|
||||
"thiserror 2.0.12",
|
||||
"uucore",
|
||||
]
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ path = "src/ptx.rs"
|
|||
clap = { workspace = true }
|
||||
regex = { workspace = true }
|
||||
uucore = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[[bin]]
|
||||
name = "ptx"
|
||||
|
|
|
@ -9,11 +9,11 @@ use clap::{Arg, ArgAction, Command};
|
|||
use regex::Regex;
|
||||
use std::cmp;
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter, Write as FmtWrite};
|
||||
use std::fmt::Write as FmtWrite;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
|
||||
use std::num::ParseIntError;
|
||||
use thiserror::Error;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult, UUsageError};
|
||||
use uucore::{format_usage, help_about, help_usage};
|
||||
|
@ -194,28 +194,18 @@ struct WordRef {
|
|||
filename: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
enum PtxError {
|
||||
#[error("There is no dumb format with GNU extensions disabled")]
|
||||
DumbFormat,
|
||||
#[error("{0} not implemented yet")]
|
||||
NotImplemented(&'static str),
|
||||
#[error("{0}")]
|
||||
ParseError(ParseIntError),
|
||||
}
|
||||
|
||||
impl Error for PtxError {}
|
||||
impl UError for PtxError {}
|
||||
|
||||
impl Display for PtxError {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::DumbFormat => {
|
||||
write!(f, "There is no dumb format with GNU extensions disabled")
|
||||
}
|
||||
Self::NotImplemented(s) => write!(f, "{s} not implemented yet"),
|
||||
Self::ParseError(e) => e.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
|
||||
let mut config = Config::default();
|
||||
let err_msg = "parsing options failed";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue