mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 18:40:39 +08:00
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:
@@ -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
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user