Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/benwilber/exitcode
- Owner: benwilber
- License: apache-2.0
- Created: 2017-05-25T19:15:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-06T08:58:59.000Z (about 2 years ago)
- Last Synced: 2024-08-08T22:34:08.191Z (3 months ago)
- Topics: exitcode, rust, sysexits
- Language: Rust
- Size: 17.6 KB
- Stars: 66
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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);}
```