Skip to content

Commit

Permalink
Merge branch 'main' into darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Mar 19, 2024
2 parents fababe1 + cac8ce8 commit 0e155eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/parse_man/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::path::PathBuf;

use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
Io(#[from] std::io::Error),

#[error("Unsupported manpage format")]
UnsupportedFormat(),
#[error("Unsupported manpage format for {path}")]
UnsupportedFormat { path: PathBuf },

#[error("Could not find manpage for {cmd_name}")]
ManpageNotFound { cmd_name: String },
Expand Down
15 changes: 9 additions & 6 deletions src/parse_man/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn get_cmd_name(manpage_path: impl AsRef<Path>) -> String {
/// Fails if none of the manpage parsers could understand the text, or if one of
/// them encountered an error.
pub fn parse_manpage_text(
path: PathBuf,
cmd_name: &str,
text: impl AsRef<str>,
) -> Result<Vec<Flag>> {
Expand All @@ -76,7 +77,7 @@ pub fn parse_manpage_text(
.collect::<Vec<_>>();

if flags.is_empty() {
Err(Error::UnsupportedFormat())
Err(Error::UnsupportedFormat { path })
} else {
Ok(flags)
}
Expand Down Expand Up @@ -124,11 +125,13 @@ pub fn parse_from(
let mut errors = Vec::new();

let flags = if let Some(path) = pre_info.path {
match read_manpage(path) {
Ok(text) => parse_manpage_text(cmd_name, text).unwrap_or_else(|e| {
errors.push(e);
Vec::new()
}),
match read_manpage(path.clone()) {
Ok(text) => {
parse_manpage_text(path, cmd_name, text).unwrap_or_else(|e| {
errors.push(e);
Vec::new()
})
}
Err(e) => {
errors.push(e.into());
Vec::new()
Expand Down

0 comments on commit 0e155eb

Please sign in to comment.