mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 22:02:03 +00:00
Custom help message when using argh
Help messages generated from argh is nearly useless and very hard to customize. Fork argh and disable all code for generating help messages. Use a closure to print the help message when handling EarlyExit.
This commit is contained in:
@@ -382,20 +382,21 @@ pub fn map_args<'a>(argc: i32, argv: *const *const c_char) -> Result<Vec<&'a Utf
|
||||
}
|
||||
|
||||
pub trait EarlyExitExt<T> {
|
||||
fn early_exit(self) -> T;
|
||||
fn on_early_exit<F: FnOnce()>(self, print_help_msg: F) -> T;
|
||||
}
|
||||
|
||||
impl<T> EarlyExitExt<T> for Result<T, EarlyExit> {
|
||||
fn early_exit(self) -> T {
|
||||
fn on_early_exit<F: FnOnce()>(self, print_help_msg: F) -> T {
|
||||
match self {
|
||||
Ok(t) => t,
|
||||
Err(EarlyExit { output, status }) => match status {
|
||||
Ok(_) => {
|
||||
eprintln!("{}", output);
|
||||
print_help_msg();
|
||||
exit(0)
|
||||
}
|
||||
Err(_) => {
|
||||
eprintln!("{}", output);
|
||||
print_help_msg();
|
||||
exit(1)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user