mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-21 12:41:13 +00:00
od: clean up returning Err
This commit is contained in:
parent
d329c7c864
commit
3ea18173cb
3 changed files with 27 additions and 46 deletions
|
|
@ -128,36 +128,27 @@ impl OdOptions {
|
|||
}
|
||||
};
|
||||
|
||||
let mut skip_bytes = match matches.value_of(options::SKIP_BYTES) {
|
||||
None => 0,
|
||||
Some(s) => match parse_number_of_bytes(s) {
|
||||
Ok(i) => i,
|
||||
Err(_) => {
|
||||
return Err(format!("Invalid argument --skip-bytes={}", s));
|
||||
}
|
||||
},
|
||||
};
|
||||
let mut skip_bytes = matches
|
||||
.value_of(options::SKIP_BYTES)
|
||||
.map(|s| {
|
||||
parse_number_of_bytes(s).map_err(|_| format!("Invalid argument --skip-bytes={}", s))
|
||||
})
|
||||
.transpose()?
|
||||
.unwrap_or(0);
|
||||
|
||||
let mut label: Option<usize> = None;
|
||||
|
||||
let input_strings = match parse_inputs(&matches) {
|
||||
Ok(CommandLineInputs::FileNames(v)) => v,
|
||||
Ok(CommandLineInputs::FileAndOffset((f, s, l))) => {
|
||||
let parsed_input = parse_inputs(&matches).map_err(|e| format!("Invalid inputs: {}", e))?;
|
||||
let input_strings = match parsed_input {
|
||||
CommandLineInputs::FileNames(v) => v,
|
||||
CommandLineInputs::FileAndOffset((f, s, l)) => {
|
||||
skip_bytes = s;
|
||||
label = l;
|
||||
vec![f]
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(format!("Invalid inputs: {}", e));
|
||||
}
|
||||
};
|
||||
|
||||
let formats = match parse_format_flags(&args) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
let formats = parse_format_flags(&args)?;
|
||||
|
||||
let mut line_bytes = match matches.value_of(options::WIDTH) {
|
||||
None => 16,
|
||||
|
|
@ -174,15 +165,12 @@ impl OdOptions {
|
|||
|
||||
let output_duplicates = matches.is_present(options::OUTPUT_DUPLICATES);
|
||||
|
||||
let read_bytes = match matches.value_of(options::READ_BYTES) {
|
||||
None => None,
|
||||
Some(s) => match parse_number_of_bytes(s) {
|
||||
Ok(i) => Some(i),
|
||||
Err(_) => {
|
||||
return Err(format!("Invalid argument --read-bytes={}", s));
|
||||
}
|
||||
},
|
||||
};
|
||||
let read_bytes = matches
|
||||
.value_of(options::READ_BYTES)
|
||||
.map(|s| {
|
||||
parse_number_of_bytes(s).map_err(|_| format!("Invalid argument --read-bytes={}", s))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let radix = match matches.value_of(options::ADDRESS_RADIX) {
|
||||
None => Radix::Octal,
|
||||
|
|
|
|||
|
|
@ -108,10 +108,8 @@ pub fn parse_format_flags(args: &[String]) -> Result<Vec<ParsedFormatterItemInfo
|
|||
|
||||
for arg in arg_iter {
|
||||
if expect_type_string {
|
||||
match parse_type_string(arg) {
|
||||
Ok(v) => formats.extend(v.into_iter()),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
let v = parse_type_string(arg)?;
|
||||
formats.extend(v.into_iter());
|
||||
expect_type_string = false;
|
||||
} else if arg.starts_with("--") {
|
||||
if arg.len() == 2 {
|
||||
|
|
@ -119,10 +117,8 @@ pub fn parse_format_flags(args: &[String]) -> Result<Vec<ParsedFormatterItemInfo
|
|||
}
|
||||
if arg.starts_with("--format=") {
|
||||
let params: String = arg.chars().skip_while(|c| *c != '=').skip(1).collect();
|
||||
match parse_type_string(¶ms) {
|
||||
Ok(v) => formats.extend(v.into_iter()),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
let v = parse_type_string(¶ms)?;
|
||||
formats.extend(v.into_iter());
|
||||
}
|
||||
if arg == "--format" {
|
||||
expect_type_string = true;
|
||||
|
|
@ -145,10 +141,8 @@ pub fn parse_format_flags(args: &[String]) -> Result<Vec<ParsedFormatterItemInfo
|
|||
}
|
||||
}
|
||||
if !format_spec.is_empty() {
|
||||
match parse_type_string(&format_spec) {
|
||||
Ok(v) => formats.extend(v.into_iter()),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
let v = parse_type_string(&format_spec)?;
|
||||
formats.extend(v.into_iter());
|
||||
expect_type_string = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,16 +36,15 @@ impl<R: Read> Read for PartialReader<R> {
|
|||
while self.skip > 0 {
|
||||
let skip_count = cmp::min(self.skip, MAX_SKIP_BUFFER);
|
||||
|
||||
match self.inner.read(&mut bytes[..skip_count]) {
|
||||
Ok(0) => {
|
||||
match self.inner.read(&mut bytes[..skip_count])? {
|
||||
0 => {
|
||||
// this is an error as we still have more to skip
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::UnexpectedEof,
|
||||
"tried to skip past end of input",
|
||||
));
|
||||
}
|
||||
Ok(n) => self.skip -= n,
|
||||
Err(e) => return Err(e),
|
||||
n => self.skip -= n,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue