die-exit-2
[die-exit-2] is a simple Rust library to make it easy to handle errors and exit in command line programs.
It is forked from die-exit, which in turn is a fork of die. The fork only
exists to publish the updated version of die-exit: the code ha updates that
were never published to crates.io. I needed an updated version on crates.io so
I could publish a crate that depends on it, so I'm publishing this fork. This
fork will be deprecated if the original crate publishes an updated version at
some point.
Cargo.toml
[]
= "0.4"
# When added, `die!()` will trigger a panic rather than exiting during development.
[]
= "0.4"
= ["test"]
Example usage:
use *;
// Result:
Ok.die; // unwraps to 1 successfully
Err.die; // prints `strange error` to stderr then exits with code 1
// Option:
Some.die; // unwraps to 1 successfully
None.die; // prints `none option` to stderr then exits with code 1
// custom error codes:
Err.die_code; // prints `strange error` to stderr then exits with code 4
None.die_code; // prints `none option` to stderr then exits with code 5
// with function (Result only):
Err.die_with; // prints `strange error: failure` to stderr then exits with code 1
Err.die_with; // prints `strange error: failure` to stderr then exits with code 6
// die! macro:
die!; // prints message to stderr then exits with code 1
die!; // prints message to stderr then exits with code 2
die!; // prints message to stderr then exits with code 3
die!; // prints `argument -e must be 1` to stderr then exits with code 4
die!; // prints `argument -e must be 1` to stderr then exits with code 1
die!; // prints nothing, only exits with code 3
die!; // prints nothing, only exits with code 1
Example testing:
Ensure that the test feature is turned on.
cargo Features
- test: Turn this on if you want to run tests where
diemight be used. This will change the behaviour ofdieand its variants to callpanic!()instead ofprocess::exit().
License
This project is licensed under the MIT license (LICENSE-MIT http://opensource.org/licenses/MIT)