mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
unexpand: move to thiserror
This commit is contained in:
parent
899c118f3f
commit
9099f342e0
3 changed files with 8 additions and 17 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3415,6 +3415,7 @@ name = "uu_unexpand"
|
|||
version = "0.0.30"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"thiserror 2.0.12",
|
||||
"unicode-width 0.2.0",
|
||||
"uucore",
|
||||
]
|
||||
|
|
|
@ -17,6 +17,7 @@ readme.workspace = true
|
|||
path = "src/unexpand.rs"
|
||||
|
||||
[dependencies]
|
||||
thiserror = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
unicode-width = { workspace = true }
|
||||
uucore = { workspace = true }
|
||||
|
|
|
@ -6,13 +6,12 @@
|
|||
// spell-checker:ignore (ToDO) nums aflag uflag scol prevtab amode ctype cwidth nbytes lastcol pctype Preprocess
|
||||
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, BufWriter, Read, Stdout, Write, stdin, stdout};
|
||||
use std::num::IntErrorKind;
|
||||
use std::path::Path;
|
||||
use std::str::from_utf8;
|
||||
use thiserror::Error;
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult, USimpleError};
|
||||
|
@ -23,30 +22,20 @@ const ABOUT: &str = help_about!("unexpand.md");
|
|||
|
||||
const DEFAULT_TABSTOP: usize = 8;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
enum ParseError {
|
||||
#[error("tab size contains invalid character(s): {}", _0.quote())]
|
||||
InvalidCharacter(String),
|
||||
#[error("tab size cannot be 0")]
|
||||
TabSizeCannotBeZero,
|
||||
#[error("tab stop value is too large")]
|
||||
TabSizeTooLarge,
|
||||
#[error("tab sizes must be ascending")]
|
||||
TabSizesMustBeAscending,
|
||||
}
|
||||
|
||||
impl Error for ParseError {}
|
||||
impl UError for ParseError {}
|
||||
|
||||
impl fmt::Display for ParseError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::InvalidCharacter(s) => {
|
||||
write!(f, "tab size contains invalid character(s): {}", s.quote())
|
||||
}
|
||||
Self::TabSizeCannotBeZero => write!(f, "tab size cannot be 0"),
|
||||
Self::TabSizeTooLarge => write!(f, "tab stop value is too large"),
|
||||
Self::TabSizesMustBeAscending => write!(f, "tab sizes must be ascending"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tabstops_parse(s: &str) -> Result<Vec<usize>, ParseError> {
|
||||
let words = s.split(',');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue