Crates.io | confu |
lib.rs | confu |
version | 0.1.3 |
source | src |
created_at | 2021-05-15 19:15:16.651941 |
updated_at | 2021-05-20 04:26:40.238566 |
description | No frills app configuration via environment or args |
homepage | https://github.com/izirku/confu |
repository | https://github.com/izirku/confu |
max_upload_size | |
id | 397967 |
size | 7,025 |
No frills app configuration via environment or command line arguments for software written in Rust.
Why Confu? Geared towards microservices, and has minimal direct dependencies
list: syn
, quote
, proc-macro2
, proc-macro-error
.
if a more user friendly command line parsing desired, there are great and proven crate alternatives. For example, Clap 👏.
debug
or release
[PREFIX]VERSION
,
otherwise is set to <unspecified>
APP_
panic
xxxxxxx
" instead of sensitive informationA working example is provided in repository. And a quick usage summary here as well:
In Cargo.toml
:
[dependencies]
confu = "*"
then, a code like this:
use confu::Confu;
#[derive(Confu)]
#[confu_prefix = "APP_"]
struct Config {
#[default = "postgres"]
db_user: String,
#[protect]
#[default = "postgres"]
db_password: String,
#[default = "127.0.0.1"]
api_host: String,
#[require]
telemetry: String,
#[hide]
super_secret_stuff: String,
}
fn main() {
let config = Config::confu();
config.show();
}
should produce something like this, granted that APP_VERSION="0.1.0"
environment variable is also set:
$ cargo run --quiet -- --app_telemetry=yes
build: debug
version: 0.1.0
APP_DB_USER/--app_db_user=postgres (default: "postgres")
APP_DB_PASSWORD/--app_db_password=xxxxxxx (default: "xxxxxxx")
APP_API_HOST/--app_api_host=127.0.0.1 (default: "127.0.0.1")
APP_TELEMETRY/--app_telemetry=yes (required)
if a require argument was omitted, a panic
will occur:
$ cargo run --quiet
thread 'main' panicked at 'required argument APP_TELEMETRY/--app_telemetry was not provided.', examples\basic\src\config.rs:4:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
bool
types