mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +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 = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"regex",
|
"regex",
|
||||||
|
"thiserror 2.0.12",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ path = "src/ptx.rs"
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
regex = { workspace = true }
|
regex = { workspace = true }
|
||||||
uucore = { workspace = true }
|
uucore = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "ptx"
|
name = "ptx"
|
||||||
|
|
|
@ -9,11 +9,11 @@ use clap::{Arg, ArgAction, Command};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||||
use std::error::Error;
|
use std::fmt::Write as FmtWrite;
|
||||||
use std::fmt::{Display, Formatter, Write as FmtWrite};
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
|
use std::io::{BufRead, BufReader, BufWriter, Read, Write, stdin, stdout};
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
use thiserror::Error;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{FromIo, UError, UResult, UUsageError};
|
use uucore::error::{FromIo, UError, UResult, UUsageError};
|
||||||
use uucore::{format_usage, help_about, help_usage};
|
use uucore::{format_usage, help_about, help_usage};
|
||||||
|
@ -194,28 +194,18 @@ struct WordRef {
|
||||||
filename: String,
|
filename: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
enum PtxError {
|
enum PtxError {
|
||||||
|
#[error("There is no dumb format with GNU extensions disabled")]
|
||||||
DumbFormat,
|
DumbFormat,
|
||||||
|
#[error("{0} not implemented yet")]
|
||||||
NotImplemented(&'static str),
|
NotImplemented(&'static str),
|
||||||
|
#[error("{0}")]
|
||||||
ParseError(ParseIntError),
|
ParseError(ParseIntError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for PtxError {}
|
|
||||||
impl UError 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> {
|
fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
let err_msg = "parsing options failed";
|
let err_msg = "parsing options failed";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue