Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/benwilber/exitcode

Preferred system exit codes as defined by sysexits.h
https://github.com/benwilber/exitcode

exitcode rust sysexits

Last synced: 11 days ago
JSON representation

Preferred system exit codes as defined by sysexits.h

Awesome Lists containing this project

README

        

[![ghit.me](https://ghit.me/badge.svg?repo=benwilber/exitcode)](https://ghit.me/repo/benwilber/exitcode) [![Build Status](https://travis-ci.org/benwilber/exitcode.svg?branch=master)](https://travis-ci.org/benwilber/exitcode) [![Crates.io](https://img.shields.io/crates/v/exitcode.svg)](https://crates.io/crates/exitcode)

# exitcode
System exit code constants as defined by [sysexits.h](https://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD+4.3-RELEASE&format=html)

Documentation is available [here](https://docs.rs/exitcode)

# Installing from [crates.io](https://crates.io/crates/exitcode)
```
[dependencies]
exitcode = "1.1.2"
```

# Example
```rust
extern crate exitcode;

use std::process;

pub fn parse_int_or_return_error_exitcode(s: String) -> Result {
match s.parse::() {
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);

}
```