proc_exit/lib.rs
1//! ## Features
2//!
3//! - `i32` newtype for exit codes
4//! - Can represent any valid exit code
5//! - Type safe, operations are restricted to what is valid for exit codes
6//! - Includes common exit codes and signal exit codes
7//! - Integrate with `main`, `std::process`, and `std::io::Error`
8//! - Supports exiting silently (error message reported through another means)
9//!
10//! ## Install
11//!
12//! Add to your `Cargo.toml`:
13//!
14//! ```console
15//! $ cargo add proc-exit
16//! ```
17//!
18//! # Example
19//!
20//! ```
21//! use proc_exit::prelude::*;
22//!
23//! fn main() {
24//! // Simple but Macro-less `main`
25//! // - Fast compiles
26//! // - Composable with other features
27//! let result = run();
28//! proc_exit::exit(result);
29//! }
30//!
31//! fn run() -> proc_exit::ExitResult {
32//! // Integrates directly with `std::io::Error`, returning the right exit code.
33//! let exit_status = std::process::Command::new("true")
34//! .status().with_code(proc_exit::Code::FAILURE)?;
35//! // Can pass `Command` exit codes right up, when appropriate
36//! proc_exit::Code::from_status(exit_status).ok()?;
37//!
38//! proc_exit::Code::SUCCESS.ok()
39//! }
40//! ```
41//!
42//! ## Relevant CLI crates
43//!
44//! Other crates that might be useful in testing command line programs.
45//! - [duct][duct] for orchestrating multiple processes.
46//! - or [commandspec][commandspec] for easier writing of commands
47//! - [rexpect][rexpect] for controlling interactive programs.
48//! - [`assert_cmd`][assert_cmd] can be reused to simplify controlling CLIs
49//!
50//! [duct]: https://crates.io/crates/duct
51//! [rexpect]: https://crates.io/crates/rexpect
52//! [assert_cmd]: https://crates.io/crates/assert_cmd
53//! [commandspec]: https://crates.io/crates/commandspec
54//!
55//! ## Alternative crates
56//!
57//! Crates considered when making this one include:
58//! - [sysexit][sysexit]
59//! - Uses an enum, making certain states unrepresentable
60//! - Includes signals
61//! - Integrates with `std::process` and `std::io::Error`
62//! - Doesn't integrate with `main`
63//! - [sysexits]
64//! - Uses an enum, making certain states unrepresentable
65//! - Doesn't include signals
66//! - Doesn't integrate with `main`, `std::process`, or `std::io::Error`
67//! - [exit-code][exit-code]
68//! - `i32` constants and helper methods
69//! - Doesn't include signals
70//! - Doesn't integrate with `main`, `std::process`, or `std::io::Error`
71//! - [exitcode][exitcode]
72//! - `i32` constants and helper methods
73//! - Doesn't include signals
74//! - Doesn't integrate with `main`, `std::process`, or `std::io::Error`
75//! - [exitfailure][exitfailure]
76//! - Allows `Display`able errors to be used with [`?` in `main()`](https://github.com/rust-lang/rust/issues/43301)
77//!
78//! [sysexit]: https://crates.io/crates/sysexit
79//! [exit-code]: https://crates.io/crates/exit-code
80//! [exitcode]: https://crates.io/crates/exitcode
81//! [exitfailure]: https://crates.io/crates/exitfailure
82
83#![cfg_attr(docsrs, feature(doc_auto_cfg))]
84#![warn(clippy::print_stderr)]
85#![warn(clippy::print_stdout)]
86
87mod code;
88mod exit;
89
90/// Easy access to traits
91pub mod prelude {
92 pub use super::WithCodeResultExt as _;
93 pub use crate::sysexits::ToSysexitsResultExt as _;
94}
95
96pub mod bash;
97pub mod sysexits;
98
99pub use code::Code;
100pub use exit::WithCodeResultExt;
101pub use exit::{exit, report};
102pub use exit::{Exit, ExitResult};