zoxide/src/main.rs

39 lines
849 B
Rust
Raw Normal View History

2022-03-06 23:37:05 +00:00
#![allow(clippy::single_component_path_imports)]
// rstest_reuse must be imported at the top of the crate.
2022-09-06 22:49:45 +00:00
#[cfg(all(test, feature = "nix-dev"))]
2022-03-06 23:37:05 +00:00
use rstest_reuse;
2022-02-16 22:46:45 +00:00
mod cmd;
mod config;
2021-01-29 21:36:18 +00:00
mod db;
mod error;
mod shell;
mod util;
2020-10-18 09:22:13 +00:00
2022-09-06 22:49:45 +00:00
use std::env;
use std::io::{self, Write};
use std::process::ExitCode;
2020-10-18 09:22:13 +00:00
2022-09-16 16:54:46 +00:00
use clap::Parser;
use crate::cmd::{Cmd, Run};
use crate::error::SilentExit;
2022-09-06 22:49:45 +00:00
pub fn main() -> ExitCode {
2020-12-13 05:45:01 +00:00
// Forcibly disable backtraces.
env::remove_var("RUST_LIB_BACKTRACE");
env::remove_var("RUST_BACKTRACE");
2022-09-06 22:49:45 +00:00
match Cmd::parse().run() {
Ok(()) => ExitCode::SUCCESS,
Err(e) => match e.downcast::<SilentExit>() {
Ok(SilentExit { code }) => code.into(),
2021-01-29 21:36:18 +00:00
Err(e) => {
2023-03-01 08:25:22 +00:00
_ = writeln!(io::stderr(), "zoxide: {e:?}");
2022-09-06 22:49:45 +00:00
ExitCode::FAILURE
2021-01-29 21:36:18 +00:00
}
2022-09-06 22:49:45 +00:00
},
2021-01-29 21:36:18 +00:00
}
}