Crates.io | cli-batteries |
lib.rs | cli-batteries |
version | 0.5.0 |
source | src |
created_at | 2022-05-22 01:35:32.746972 |
updated_at | 2023-04-18 12:44:55.041205 |
description | Batteries included opinionated command line interfaces |
homepage | https://github.com/recmo/cli-batteries |
repository | https://github.com/recmo/cli-batteries |
max_upload_size | |
id | 591000 |
size | 97,515 |
Opinionated batteries-included command line interface runtime utilities.
To use it, add it to your Cargo.toml
[dependencies]
cli-batteries = "0.1"
[build-dependencies]
cli-batteries = "0.1"
and call the [build_rs
] function in your build.rs
fn main() {
cli_batteries::build_rs().unwrap()
}
Then in your src/main.rs
you define app specific command line arguments using [clap::Parser
][clap] and run the app as follows
use cli_batteries::{version, Parser};
use std::{path::PathBuf, io::Result};
use tokio::fs::File;
#[derive(Parser)]
#[group(skip)]
struct Options {
/// File to read
#[clap(long, env, default_value = "Readme.md")]
file: PathBuf,
}
async fn app(options: Options) -> Result<()> {
let mut file = File::open(options.file).await?;
Ok(())
}
fn main() {
cli_batteries::run(version!(), app);
}
You can see this working in the example project.
signals
: Handle Ctrl-C, SIGINT and SIGTERM with gracefull shutdown.mimalloc
: Use the mimalloc allocator with security hardening features enabled.rand
: Log and configure random seeds.rayon
: Log and configure number of threads.prometheus
: Start a Prometheus metrics server.metered-allocator
: Collect metric on memory allocation, enables prometheus
.mock-shutdown
: Enable the reset_shutdown
function that allows re-arming shutdown for testing.tokio-console
: Enable the --tokio-console
option to start a Tokio console server on http://127.0.0.1:6669/
for async inspection.otlp
: Enable the --trace-otlp
option to push traces to an OpenTelementry collector.Format, lint, build and test everything (I recommend creating a shell alias for this):
cargo fmt &&\
cargo clippy --all-features --all-targets &&\
cargo test --workspace --all-features --doc -- --nocapture &&\
cargo test --workspace --all-features --all-targets -- --nocapture &&\
cargo doc --workspace --all-features --no-deps
Check documentation coverage
RUSTDOCFLAGS="-Z unstable-options --show-coverage" cargo doc --workspace --all-features --no-deps
Goals:
Maybe: