Terminal handler for `main`. clap's own display kinds (`--help`, `--version`, and the `arg_required_else_help` variant) are passed through untouched, including clap's original exit code. Everything else is re-rendered and exits 2, which means the command did not run.
(err: clap::Error, root: &clap::Command, argv: &[OsString])
| 721 | /// clap's original exit code. Everything else is re-rendered and exits 2, which |
| 722 | /// means the command did not run. |
| 723 | pub fn render_and_exit(err: clap::Error, root: &clap::Command, argv: &[OsString]) -> ! { |
| 724 | match err.kind() { |
| 725 | ErrorKind::DisplayHelp |
| 726 | | ErrorKind::DisplayVersion |
| 727 | | ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand => { |
| 728 | let _ = err.print(); |
| 729 | std::process::exit(err.exit_code()); |
| 730 | } |
| 731 | _ => { |
| 732 | let output = render(&err, root, argv); |
| 733 | write_ignoring_errors(std::io::stderr().lock(), &output); |
| 734 | std::process::exit(2); |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | #[cfg(test)] |
| 740 | mod tests { |
no test coverage detected