Crates.io | exitcode |
lib.rs | exitcode |
version | 1.1.2 |
source | src |
created_at | 2017-05-25 19:37:52.184217 |
updated_at | 2017-06-18 18:21:36.405587 |
description | Preferred system exit codes as defined by sysexits.h |
homepage | https://github.com/benwilber/exitcode |
repository | https://github.com/benwilber/exitcode |
max_upload_size | |
id | 15974 |
size | 18,193 |
System exit code constants as defined by sysexits.h
Documentation is available here
[dependencies]
exitcode = "1.1.2"
extern crate exitcode;
use std::process;
pub fn parse_int_or_return_error_exitcode(s: String) -> Result<i32, exitcode::ExitCode> {
match s.parse::<i32>() {
Ok(i) => Ok(i),
Err(_) => Err(exitcode::USAGE)
}
}
pub fn main() {
match parse_int_or_return_error_exitcode("123".to_string()) {
Ok(i) => println!("Parsed: {}", i),
Err(code) => {
println!("Parse error. Exiting with code: {}", code);
process::exit(code);
}
}
match parse_int_or_return_error_exitcode("foo".to_string()) {
Ok(i) => println!("Parsed: {}", i),
Err(code) => {
println!("Parse error. Exiting with code: {}", code);
process::exit(code);
}
}
println!("Exiting with code: {}", exitcode::OK);
process::exit(exitcode::OK);
}