Crates.io | axocli |
lib.rs | axocli |
version | 0.2.0 |
source | src |
created_at | 2023-04-04 01:28:26.070781 |
updated_at | 2024-02-16 00:49:04.291423 |
description | common code for setting up a CLI App and handling errors/printing. |
homepage | |
repository | https://github.com/axodotdev/axocli |
max_upload_size | |
id | 829646 |
size | 57,626 |
Common code for setting up a CLI App and handling errors/printing.
See examples/axoapp.rs for a walkthrough/example.
Some various interesting example invocations to play with:
# clap help
cargo run --example axoapp -- --help
# success
cargo run --example axoapp -- 5
cargo run --example axoapp -- 5 --output-format=json
# normal error
cargo run --example axoapp -- 2
cargo run --example axoapp -- 2 --output-format=json
# panic (setting RUST_BACKTRACE=1 here is also interesting)
cargo run --example axoapp -- 0
cargo run --example axoapp -- 0 --output-format=json
# clap error
cargo run --example axoapp --
First off, it handles setting up:
It also handles printing top-level errors, notably including a json_errors mode where the error gets formatted to json and printed to stdout, while still printing a human-friendly version to stderr. This is done for both an error returned from real_main and panics. So anything expecting machine-readable output from our apps will not freak out and get something unparseable when things error/panic. It will also set the process exit code on error (with std::process::exit, on the assumption that all cleanup was done when we returned/panicked out of real_main).
It also exposes the json diagnostic formatting machinery so you can Write them wherever or turn them into serde_json::Values. This is useful for returning a larger result with diagnostics nested inside of it (say, for reporting warnings).
Licensed under either of
at your option.