#stderr #exit #cmd-line #cmd #command-line

die

Handle errors and exit in command line programs easily

2 unstable releases

Uses old Rust 2015

0.2.0 Feb 22, 2019
0.1.0 Feb 22, 2019

#5 in #cmd-line

Download history 34/week @ 2023-11-29 58/week @ 2023-12-06 37/week @ 2023-12-13 40/week @ 2023-12-20 56/week @ 2023-12-27 512/week @ 2024-01-03 379/week @ 2024-01-10 86/week @ 2024-01-17 32/week @ 2024-01-24 33/week @ 2024-01-31 59/week @ 2024-02-07 75/week @ 2024-02-14 94/week @ 2024-02-21 77/week @ 2024-02-28 90/week @ 2024-03-06 52/week @ 2024-03-13

331 downloads per month
Used in 13 crates (12 directly)

MIT/Apache

12KB
102 lines

die

Build Status Latest Version Documentation

die is a simple Rust library to make it easy to handle errors and exit in command line programs.

# Cargo.toml
[dependencies]
die = "0.2"

Example usage:

use die::Die;
// Result:
Ok(1).die("no number"); // unwraps to 1 successfully
Err("failure").die("strange error"); // prints `strange error` to stderr then exits with code 1

// Option: 
Some(1).die("no number"); // unwraps to 1 successfully
None.die("none option"); // prints `none option` to stderr then exits with code 1

// custom error codes:
Err("failure").die_code("strange error", 4); // prints `strange error` to stderr then exits with code 4
None.die_code("none option", 5); // prints `none option` to stderr then exits with code 5

// die! macro:
die!("argument to -e must be numeric"); // prints message to stderr then exits with code 1
die!(2; "argument to -e must be numeric"); // prints message to stderr then exits with code 2
die!("argument to -e must be numeric"; 3); // prints message to stderr then exits with code 3
die!("argument {} must be {}", "-e", 1; 4); // prints `argument -e must be 1` to stderr then exits with code 4
die!("argument {} must be {}", "-e", 1); // prints `argument -e must be 1` to stderr then exits with code 1
die!(2); // prints nothing, only exits with code 3
die!(); // prints nothing, only exits with code 1

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in die by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps