mirror of
https://github.com/dandavison/delta.git
synced 2024-10-05 12:27:35 +03:00
Add fatal() function to handle exiting on errors
Panic when testing or exit with return value 2.
This commit is contained in:
parent
85ba3ba578
commit
636b56729b
@ -13,6 +13,7 @@ use crate::cli;
|
||||
use crate::color;
|
||||
use crate::delta::State;
|
||||
use crate::env;
|
||||
use crate::fatal;
|
||||
use crate::features::navigate;
|
||||
use crate::features::side_by_side;
|
||||
use crate::git_config::{GitConfig, GitConfigEntry};
|
||||
@ -193,10 +194,7 @@ impl From<cli::Opt> for Config {
|
||||
// Note that "default" is not documented
|
||||
Some("ansi") | Some("default") | None => BgFillMethod::TryAnsiSequence,
|
||||
Some("spaces") => BgFillMethod::Spaces,
|
||||
_ => {
|
||||
eprintln!("Invalid option for line-fill-method: Expected \"ansi\" or \"spaces\".");
|
||||
process::exit(1);
|
||||
}
|
||||
_ => fatal("Invalid option for line-fill-method: Expected \"ansi\" or \"spaces\"."),
|
||||
};
|
||||
|
||||
let navigate_regexp = if opt.navigate || opt.show_themes {
|
||||
|
13
src/main.rs
13
src/main.rs
@ -35,6 +35,19 @@ use crate::bat_utils::assets::{list_languages, HighlightingAssets};
|
||||
use crate::bat_utils::output::OutputType;
|
||||
use crate::delta::delta;
|
||||
|
||||
pub fn fatal<T>(errmsg: T) -> !
|
||||
where
|
||||
T: AsRef<str> + std::fmt::Display,
|
||||
{
|
||||
#[cfg(not(test))]
|
||||
{
|
||||
eprintln!("{}", errmsg);
|
||||
process::exit(2);
|
||||
}
|
||||
#[cfg(test)]
|
||||
panic!("{}\n", errmsg);
|
||||
}
|
||||
|
||||
pub mod errors {
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
|
Loading…
Reference in New Issue
Block a user