https://github.com/recmo/cli-batteries
Batteries included command line interfaces.
https://github.com/recmo/cli-batteries
Last synced: 3 months ago
JSON representation
Batteries included command line interfaces.
- Host: GitHub
- URL: https://github.com/recmo/cli-batteries
- Owner: recmo
- License: mit
- Created: 2022-05-21T18:54:30.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-18T08:15:59.000Z (almost 2 years ago)
- Last Synced: 2025-04-14T19:06:36.887Z (3 months ago)
- Language: Rust
- Size: 314 KB
- Stars: 22
- Watchers: 2
- Forks: 3
- Open Issues: 17
-
Metadata Files:
- Readme: Readme.md
- Changelog: Changelog.md
- License: mit-license.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# CLI Batteries
[](https://crates.io/crates/cli-batteries)
[](https://docs.rs/cli-batteries)
[](https://github.com/recmo/cli-batteries/blob/main/mit-license.md)
[](https://deps.rs/repo/github/recmo/cli-batteries)
[](https://codecov.io/gh/recmo/cli-batteries)
[](https://github.com/recmo/cli-batteries/actions/workflows/ci.yml)Opinionated batteries-included command line interface runtime utilities.
To use it, add it to your `Cargo.toml`
```toml
[dependencies]
cli-batteries = "0.1"[build-dependencies]
cli-batteries = "0.1"
```and call the [`build_rs`] function in your `build.rs`
```rust,ignore
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
```rust,ignore
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](./example).
## Features
* `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.[mimalloc]: https://github.com/microsoft/mimalloc
## Building and testing
Format, lint, build and test everything (I recommend creating a shell alias for this):
```sh
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
```sh
RUSTDOCFLAGS="-Z unstable-options --show-coverage" cargo doc --workspace --all-features --no-deps
```## To do
Goals:
Maybe:
---
[](https://github.com/recmo/cli-batteries)
[](https://github.com/recmo/cli-batteries/graphs/contributors)
[](https://github.com/recmo/cli-batteries/issues)
[](https://github.com/recmo/cli-batteries/pulls)
[](https://star-history.com/#recmo/cli-batteries&Date)
[](https://crates.io/crates/cli-batteries)