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

die

轻松处理命令行程序中的错误和退出

2 个不稳定版本

使用旧的 Rust 2015

0.2.0 2019年2月22日
0.1.0 2019年2月22日

#4#cmd-line

Download history 101/week @ 2024-04-02 55/week @ 2024-04-09 84/week @ 2024-04-16 77/week @ 2024-04-23 47/week @ 2024-04-30 89/week @ 2024-05-07 216/week @ 2024-05-14 275/week @ 2024-05-21 341/week @ 2024-05-28 322/week @ 2024-06-04 322/week @ 2024-06-11 346/week @ 2024-06-18 323/week @ 2024-06-25 256/week @ 2024-07-02 560/week @ 2024-07-09 75/week @ 2024-07-16

1,279 每月下载量
13 个 crate(12 个直接)中使用

MIT/Apache

12KB
102

die

Build Status Latest Version Documentation

die 是一个简单的 Rust 库,用于使处理命令行程序中的错误和退出变得简单。

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

示例用法

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

许可证

本项目根据您的选择,受以下任一许可证的约束:

贡献

除非您明确声明,否则任何有意提交给 die 包含在内的贡献,根据 Apache-2.0 许可证的定义,应按上述方式双重授权,不附加任何额外条款或条件。

无运行时依赖