[−][src]Crate proc_exit
Features
i32
newtype for exit codes- Can represent any valid exit code
- Type safe, operations are restricted to what is valid for exit codes
- Includes standard exit codes and signal exit codes
- Integrate with
main
,std::process
, andstd::io::Error
- Supports exiting silently (error message reported through another means)
Install
Add to your Cargo.toml
:
[dependencies]
proc-exit = "1.0.1"
Feature flags:
portable
: Coerce exit codes tou8
for consistent, cross-platform, behavior
Example
fn main() { // Simple but Macro-less `main` // - Fast compiles // - Composable with other features let result = run(); proc_exit::exit(result); } fn run() -> proc_exit::ExitResult { // Integrates directly with `std::io::Error`, returning the right exit code. let exit_status = std::process::Command::new("true") .status()?; // Can pass `Command` exit codes right up, when appropriate proc_exit::Code::from_status(exit_status).ok()?; proc_exit::Code::SUCCESS.ok() }
Relevant crates
Other crates that might be useful in testing command line programs.
- duct for orchestrating multiple processes.
- or commandspec for easier writing of commands
- rexpect for controlling interactive programs.
assert_cmd
can be reused to simplify controlling CLIs
Related crates
Some crates that fill a similar role include:
- sysexit
- Uses an enum, making certain states unpresentable
- Includes signals
- Integrates with
std::process
andstd::io::Error
- Doesn't integrate with
main
- exit-code
i32
constants and helper methods- Doesn't include signals
- Doesn't integrate with
main
,std::process
, orstd::io::Error
- exitcode
i32
constants and helper methods- Doesn't include signals
- Doesn't integrate with
main
,std::process
, orstd::io::Error
- exitfailure
- Allows
Display
able errors to be used with?
inmain()
- Allows
References
As a basis it encodes the exit codes of sysexits(3) from OpenBSD (64-78), exit statuses used by bash,
supplemented by codes created by shells when the command is terminated
by a fatal signal. When the fatal signal is a number N, the latter
follows bash's strategy of using the value 128 + N as the exit status.
This means that the SIGHUP
(1) signal will be recognised as the exit code
for the number 129. Signal codes were taken from wikipedia
Structs
Code | Process exit code. |
Exit | Error type for exiting programs. |
Traits
WithCodeResultExt | Extension for converting errors to |
Functions
exit | Report any error message and exit. |
report | Report, delegating exiting to the caller. |
Type Definitions
ExitResult |