Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace exitcode with sysexits #179

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/in-depth/exit-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,32 @@ Beyond that, people have done many things in their programs.
So, what to do?
The BSD ecosystem has collected a common definition for their exit codes
(you can find them [here][`sysexits.h`]).
The Rust library [`exitcode`] provides these same codes,
The Rust library [`sysexits`] provides these same codes,
ready to be used in your application.
Please see its API documentation for the possible values to use.

After you add the `exitcode` dependency to your `Cargo.toml`,
you can use it like this:

```rust,ignore
fn main() {
fn main() -> sysexits::ExitCode {
// ...actual work...
match result {
Ok(_) => {
println!("Done!");
std::process::exit(exitcode::OK);
sysexits::ExitCode::Ok
}
Err(CustomError::CantReadConfig(e)) => {
eprintln!("Error: {}", e);
std::process::exit(exitcode::CONFIG);
sysexits::ExitCode::Config
}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(exitcode::DATAERR);
sysexits::ExitCode::DataErr
}
}
}
```


[`exitcode`]: https://crates.io/crates/exitcode
[`sysexits`]: https://crates.io/crates/sysexits
[`sysexits.h`]: https://www.freebsd.org/cgi/man.cgi?query=sysexits&apropos=0&sektion=0&manpath=FreeBSD+11.2-stable&arch=default&format=html