Skip to content

Commit

Permalink
Fix clippy::map_unwrap_or.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcampbell24 committed Sep 20, 2024
1 parent dfa2322 commit 418cd10
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/uu/pr/src/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,14 +731,14 @@ fn build_options(
let offset_spaces = " ".repeat(parse_usize(matches, options::INDENT).unwrap_or(Ok(0))?);
let join_lines = matches.get_flag(options::JOIN_LINES);

let col_sep_for_printing = column_mode_options
.as_ref()
.map(|i| i.column_separator.clone())
.unwrap_or_else(|| {
let col_sep_for_printing = column_mode_options.as_ref().map_or_else(
|| {
merge_files_print
.map(|_k| DEFAULT_COLUMN_SEPARATOR.to_string())
.unwrap_or_default()
});
},
|i| i.column_separator.clone(),
);

let columns_to_print =
merge_files_print.unwrap_or_else(|| column_mode_options.as_ref().map_or(1, |i| i.columns));
Expand Down Expand Up @@ -783,8 +783,9 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
return Ok(Box::new(stdin) as Box<dyn Read>);
}

metadata(path)
.map(|i| {
metadata(path).map_or_else(
|_| Err(PrError::NotExists(path.to_string())),
|i| {
let path_string = path.to_string();
match i.file_type() {
#[cfg(unix)]
Expand All @@ -801,13 +802,19 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
}
_ => Err(PrError::UnknownFiletype(path_string)),
}
})
.unwrap_or_else(|_| Err(PrError::NotExists(path.to_string())))
},
)
}

fn split_lines_if_form_feed(file_content: Result<String, std::io::Error>) -> Vec<FileLine> {
file_content
.map(|content| {
file_content.map_or_else(
|e| {
vec![FileLine {
line_content: Err(e),

Check warning on line 813 in src/uu/pr/src/pr.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/pr/src/pr.rs#L811-L813

Added lines #L811 - L813 were not covered by tests
..FileLine::default()
}]
},

Check warning on line 816 in src/uu/pr/src/pr.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/pr/src/pr.rs#L816

Added line #L816 was not covered by tests
|content| {
let mut lines = Vec::new();
let mut f_occurred = 0;
let mut chunk = Vec::new();
Expand Down Expand Up @@ -836,13 +843,8 @@ fn split_lines_if_form_feed(file_content: Result<String, std::io::Error>) -> Vec
});

lines
})
.unwrap_or_else(|e| {
vec![FileLine {
line_content: Err(e),
..FileLine::default()
}]
})
},
)
}

fn pr(path: &str, options: &OutputOptions) -> Result<i32, PrError> {
Expand Down

0 comments on commit 418cd10

Please sign in to comment.