1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 20:47:46 +00:00

Merge pull request #3539 from jfinkels/seq-usage-error

seq: use usage error where appropriate
This commit is contained in:
Sylvestre Ledru 2022-05-20 10:26:55 +02:00 committed by GitHub
commit ae7d8aac46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,20 +31,20 @@ impl SeqError {
/// The [`String`] argument as read from the command-line. /// The [`String`] argument as read from the command-line.
fn arg(&self) -> &str { fn arg(&self) -> &str {
match self { match self {
SeqError::ParseError(s, _) => s, Self::ParseError(s, _) => s,
SeqError::ZeroIncrement(s) => s, Self::ZeroIncrement(s) => s,
} }
} }
/// The type of argument that is causing the error. /// The type of argument that is causing the error.
fn argtype(&self) -> &str { fn argtype(&self) -> &str {
match self { match self {
SeqError::ParseError(_, e) => match e { Self::ParseError(_, e) => match e {
ParseNumberError::Float => "floating point argument", ParseNumberError::Float => "floating point argument",
ParseNumberError::Nan => "'not-a-number' argument", ParseNumberError::Nan => "'not-a-number' argument",
ParseNumberError::Hex => "hexadecimal argument", ParseNumberError::Hex => "hexadecimal argument",
}, },
SeqError::ZeroIncrement(_) => "Zero increment value", Self::ZeroIncrement(_) => "Zero increment value",
} }
} }
} }
@ -53,18 +53,16 @@ impl UError for SeqError {
fn code(&self) -> i32 { fn code(&self) -> i32 {
1 1
} }
fn usage(&self) -> bool {
true
}
} }
impl Error for SeqError {} impl Error for SeqError {}
impl Display for SeqError { impl Display for SeqError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!( write!(f, "invalid {}: {}", self.argtype(), self.arg().quote())
f,
"invalid {}: {}\nTry '{} --help' for more information.",
self.argtype(),
self.arg().quote(),
uucore::execution_phrase(),
)
} }
} }