mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Add ParseSizeError::PhysicalMem enum variant
This commit is contained in:
parent
6a5f2aa334
commit
39847a741a
6 changed files with 19 additions and 7 deletions
|
@ -517,9 +517,7 @@ fn parse_bytes_no_x(full: &str, s: &str) -> Result<u64, ParseError> {
|
||||||
(None, None, None) => match parser.parse_u64(s) {
|
(None, None, None) => match parser.parse_u64(s) {
|
||||||
Ok(n) => (n, 1),
|
Ok(n) => (n, 1),
|
||||||
Err(ParseSizeError::SizeTooBig(_)) => (u64::MAX, 1),
|
Err(ParseSizeError::SizeTooBig(_)) => (u64::MAX, 1),
|
||||||
Err(ParseSizeError::InvalidSuffix(_) | ParseSizeError::ParseFailure(_)) => {
|
Err(_) => return Err(ParseError::InvalidNumber(full.to_string())),
|
||||||
return Err(ParseError::InvalidNumber(full.to_string()))
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
(Some(i), None, None) => (parse_bytes_only(s, i)?, 1),
|
(Some(i), None, None) => (parse_bytes_only(s, i)?, 1),
|
||||||
(None, Some(i), None) => (parse_bytes_only(s, i)?, 2),
|
(None, Some(i), None) => (parse_bytes_only(s, i)?, 2),
|
||||||
|
|
|
@ -189,6 +189,7 @@ impl Options {
|
||||||
.to_string(),
|
.to_string(),
|
||||||
),
|
),
|
||||||
ParseSizeError::ParseFailure(s) => OptionsError::InvalidBlockSize(s),
|
ParseSizeError::ParseFailure(s) => OptionsError::InvalidBlockSize(s),
|
||||||
|
ParseSizeError::PhysicalMem(s) => OptionsError::InvalidBlockSize(s),
|
||||||
})?,
|
})?,
|
||||||
header_mode: {
|
header_mode: {
|
||||||
if matches.get_flag(OPT_HUMAN_READABLE_BINARY)
|
if matches.get_flag(OPT_HUMAN_READABLE_BINARY)
|
||||||
|
|
|
@ -1120,7 +1120,9 @@ fn format_error_message(error: &ParseSizeError, s: &str, option: &str) -> String
|
||||||
ParseSizeError::InvalidSuffix(_) => {
|
ParseSizeError::InvalidSuffix(_) => {
|
||||||
format!("invalid suffix in --{} argument {}", option, s.quote())
|
format!("invalid suffix in --{} argument {}", option, s.quote())
|
||||||
}
|
}
|
||||||
ParseSizeError::ParseFailure(_) => format!("invalid --{} argument {}", option, s.quote()),
|
ParseSizeError::ParseFailure(_) | ParseSizeError::PhysicalMem(_) => {
|
||||||
|
format!("invalid --{} argument {}", option, s.quote())
|
||||||
|
}
|
||||||
ParseSizeError::SizeTooBig(_) => format!("--{} argument {} too large", option, s.quote()),
|
ParseSizeError::SizeTooBig(_) => format!("--{} argument {} too large", option, s.quote()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -626,7 +626,9 @@ fn format_error_message(error: &ParseSizeError, s: &str, option: &str) -> String
|
||||||
ParseSizeError::InvalidSuffix(_) => {
|
ParseSizeError::InvalidSuffix(_) => {
|
||||||
format!("invalid suffix in --{} argument {}", option, s.quote())
|
format!("invalid suffix in --{} argument {}", option, s.quote())
|
||||||
}
|
}
|
||||||
ParseSizeError::ParseFailure(_) => format!("invalid --{} argument {}", option, s.quote()),
|
ParseSizeError::ParseFailure(_) | ParseSizeError::PhysicalMem(_) => {
|
||||||
|
format!("invalid --{} argument {}", option, s.quote())
|
||||||
|
}
|
||||||
ParseSizeError::SizeTooBig(_) => format!("--{} argument {} too large", option, s.quote()),
|
ParseSizeError::SizeTooBig(_) => format!("--{} argument {} too large", option, s.quote()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1845,7 +1845,9 @@ fn format_error_message(error: &ParseSizeError, s: &str, option: &str) -> String
|
||||||
ParseSizeError::InvalidSuffix(_) => {
|
ParseSizeError::InvalidSuffix(_) => {
|
||||||
format!("invalid suffix in --{} argument {}", option, s.quote())
|
format!("invalid suffix in --{} argument {}", option, s.quote())
|
||||||
}
|
}
|
||||||
ParseSizeError::ParseFailure(_) => format!("invalid --{} argument {}", option, s.quote()),
|
ParseSizeError::ParseFailure(_) | ParseSizeError::PhysicalMem(_) => {
|
||||||
|
format!("invalid --{} argument {}", option, s.quote())
|
||||||
|
}
|
||||||
ParseSizeError::SizeTooBig(_) => format!("--{} argument {} too large", option, s.quote()),
|
ParseSizeError::SizeTooBig(_) => format!("--{} argument {} too large", option, s.quote()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,6 +327,9 @@ pub enum ParseSizeError {
|
||||||
|
|
||||||
/// Overflow
|
/// Overflow
|
||||||
SizeTooBig(String),
|
SizeTooBig(String),
|
||||||
|
|
||||||
|
/// Could not determine total physical memory size.
|
||||||
|
PhysicalMem(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for ParseSizeError {
|
impl Error for ParseSizeError {
|
||||||
|
@ -335,6 +338,7 @@ impl Error for ParseSizeError {
|
||||||
Self::InvalidSuffix(ref s) => s,
|
Self::InvalidSuffix(ref s) => s,
|
||||||
Self::ParseFailure(ref s) => s,
|
Self::ParseFailure(ref s) => s,
|
||||||
Self::SizeTooBig(ref s) => s,
|
Self::SizeTooBig(ref s) => s,
|
||||||
|
Self::PhysicalMem(ref s) => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +346,10 @@ impl Error for ParseSizeError {
|
||||||
impl fmt::Display for ParseSizeError {
|
impl fmt::Display for ParseSizeError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
let s = match self {
|
let s = match self {
|
||||||
Self::InvalidSuffix(s) | Self::ParseFailure(s) | Self::SizeTooBig(s) => s,
|
Self::InvalidSuffix(s)
|
||||||
|
| Self::ParseFailure(s)
|
||||||
|
| Self::SizeTooBig(s)
|
||||||
|
| Self::PhysicalMem(s) => s,
|
||||||
};
|
};
|
||||||
write!(f, "{s}")
|
write!(f, "{s}")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue