cli: Open manual on `rad help`
This commit is contained in:
parent
6d791ee143
commit
725660ed51
|
|
@ -44,19 +44,12 @@ pub struct Options {}
|
||||||
|
|
||||||
impl Args for Options {
|
impl Args for Options {
|
||||||
fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
|
fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
|
||||||
use lexopt::prelude::*;
|
|
||||||
|
|
||||||
let mut parser = lexopt::Parser::from_args(args);
|
let mut parser = lexopt::Parser::from_args(args);
|
||||||
|
|
||||||
if let Some(arg) = parser.next()? {
|
if let Some(arg) = parser.next()? {
|
||||||
match arg {
|
return Err(anyhow::anyhow!(arg.unexpected()));
|
||||||
Long("help") | Short('h') => {
|
|
||||||
return Err(Error::Help.into());
|
|
||||||
}
|
|
||||||
_ => return Err(anyhow::anyhow!(arg.unexpected())),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok((Options {}, vec![]))
|
Err(Error::HelpManual { name: "rad" }.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -302,7 +302,7 @@ impl Args for Options {
|
||||||
quiet = true;
|
quiet = true;
|
||||||
}
|
}
|
||||||
Long("help") => {
|
Long("help") => {
|
||||||
return Err(Error::HelpManual.into());
|
return Err(Error::HelpManual { name: "rad-patch" }.into());
|
||||||
}
|
}
|
||||||
Short('h') => {
|
Short('h') => {
|
||||||
return Err(Error::Help.into());
|
return Err(Error::Help.into());
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,8 @@ where
|
||||||
term::help(help.name, help.version, help.description, help.usage);
|
term::help(help.name, help.version, help.description, help.usage);
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
Some(Error::HelpManual) => {
|
Some(Error::HelpManual { name }) => {
|
||||||
let Ok(status) = term::manual(help.name) else {
|
let Ok(status) = term::manual(name) else {
|
||||||
io::error(format!("rad {}: failed to load manual page", help.name));
|
io::error(format!("rad {}: failed to load manual page", help.name));
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ pub enum Error {
|
||||||
Help,
|
Help,
|
||||||
/// If this error is returned from argument parsing, the manual page is displayed.
|
/// If this error is returned from argument parsing, the manual page is displayed.
|
||||||
#[error("help manual invoked")]
|
#[error("help manual invoked")]
|
||||||
HelpManual,
|
HelpManual { name: &'static str },
|
||||||
/// If this error is returned from argument parsing, usage is displayed.
|
/// If this error is returned from argument parsing, usage is displayed.
|
||||||
#[error("usage invoked")]
|
#[error("usage invoked")]
|
||||||
Usage,
|
Usage,
|
||||||
|
|
|
||||||
|
|
@ -139,9 +139,7 @@ pub fn help(name: &str, version: &str, description: &str, usage: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn manual(name: &str) -> io::Result<process::ExitStatus> {
|
pub fn manual(name: &str) -> io::Result<process::ExitStatus> {
|
||||||
let mut child = process::Command::new("man")
|
let mut child = process::Command::new("man").arg(name).spawn()?;
|
||||||
.arg(format!("rad-{name}"))
|
|
||||||
.spawn()?;
|
|
||||||
|
|
||||||
child.wait()
|
child.wait()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue