cli: rad patch --help opens man page

This is the same behavior as `git`. We also update the man page to have
the full list of commands and flags.
This commit is contained in:
cloudhead
2023-09-01 15:17:41 +02:00
parent b1213931de
commit 8d5299fe85
5 changed files with 99 additions and 18 deletions
+4 -1
View File
@@ -242,7 +242,10 @@ impl Args for Options {
Long("verbose") | Short('v') => {
verbose = true;
}
Long("help") | Short('h') => {
Long("help") => {
return Err(Error::HelpManual.into());
}
Short('h') => {
return Err(Error::Help.into());
}
+21 -10
View File
@@ -76,28 +76,30 @@ where
opts
}
Err(err) => {
match err.downcast_ref::<Error>() {
let hint = match err.downcast_ref::<Error>() {
Some(Error::Help) => {
term::help(help.name, help.version, help.description, help.usage);
process::exit(0);
}
Some(Error::HelpManual) => {
let Ok(status) = term::manual(help.name) else {
perror(help.name, "failed to load manual page");
process::exit(1);
};
process::exit(status.code().unwrap_or(0));
}
Some(Error::Usage) => {
term::usage(help.name, help.usage);
process::exit(1);
}
_ => {}
Some(Error::WithHint { hint, .. }) => Some(hint),
None => None,
};
eprintln!(
"{} {} rad {}: {err}",
Paint::red(ERROR_PREFIX),
Paint::red("Error:"),
help.name,
);
perror(help.name, &err);
if let Some(Error::WithHint { hint, .. }) = err.downcast_ref::<Error>() {
if let Some(hint) = hint {
eprintln!("{}", Paint::yellow(hint));
}
process::exit(1);
}
};
@@ -123,6 +125,15 @@ pub fn profile() -> Result<Profile, anyhow::Error> {
}
}
pub fn perror(name: &str, err: impl std::fmt::Display) {
eprintln!(
"{} {} rad {}: {err}",
Paint::red(ERROR_PREFIX),
Paint::red("Error:"),
name,
);
}
pub fn fail(header: &str, error: &anyhow::Error) {
let err = error.to_string();
let err = err.trim_end();
+3
View File
@@ -15,6 +15,9 @@ pub enum Error {
/// If this error is returned from argument parsing, help is displayed.
#[error("help invoked")]
Help,
/// If this error is returned from argument parsing, the manual page is displayed.
#[error("help manual invoked")]
HelpManual,
/// If this error is returned from argument parsing, usage is displayed.
#[error("usage invoked")]
Usage,