cli: Open manual on `rad help`

This commit is contained in:
cloudhead 2023-11-22 15:05:53 +01:00
parent 6d791ee143
commit 725660ed51
No known key found for this signature in database
5 changed files with 7 additions and 16 deletions

View File

@ -44,19 +44,12 @@ pub struct Options {}
impl Args for Options {
fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
use lexopt::prelude::*;
let mut parser = lexopt::Parser::from_args(args);
if let Some(arg) = parser.next()? {
match arg {
Long("help") | Short('h') => {
return Err(Error::Help.into());
}
_ => return Err(anyhow::anyhow!(arg.unexpected())),
}
return Err(anyhow::anyhow!(arg.unexpected()));
}
Ok((Options {}, vec![]))
Err(Error::HelpManual { name: "rad" }.into())
}
}

View File

@ -302,7 +302,7 @@ impl Args for Options {
quiet = true;
}
Long("help") => {
return Err(Error::HelpManual.into());
return Err(Error::HelpManual { name: "rad-patch" }.into());
}
Short('h') => {
return Err(Error::Help.into());

View File

@ -84,8 +84,8 @@ where
term::help(help.name, help.version, help.description, help.usage);
process::exit(0);
}
Some(Error::HelpManual) => {
let Ok(status) = term::manual(help.name) else {
Some(Error::HelpManual { name }) => {
let Ok(status) = term::manual(name) else {
io::error(format!("rad {}: failed to load manual page", help.name));
process::exit(1);
};

View File

@ -19,7 +19,7 @@ pub enum Error {
Help,
/// If this error is returned from argument parsing, the manual page is displayed.
#[error("help manual invoked")]
HelpManual,
HelpManual { name: &'static str },
/// If this error is returned from argument parsing, usage is displayed.
#[error("usage invoked")]
Usage,

View File

@ -139,9 +139,7 @@ pub fn help(name: &str, version: &str, description: &str, usage: &str) {
}
pub fn manual(name: &str) -> io::Result<process::ExitStatus> {
let mut child = process::Command::new("man")
.arg(format!("rad-{name}"))
.spawn()?;
let mut child = process::Command::new("man").arg(name).spawn()?;
child.wait()
}