{"id":13502926,"url":"https://github.com/bnjjj/twelf","last_synced_at":"2025-04-05T04:12:12.453Z","repository":{"id":37730507,"uuid":"311476712","full_name":"bnjjj/twelf","owner":"bnjjj","description":"Twelf is a configuration solution for Rust including 12-Factor support. It is designed with layers in order to configure different sources and formats to build your configuration. The main goal is to be very simple using a proc macro.","archived":false,"fork":false,"pushed_at":"2024-05-27T06:09:57.000Z","size":95,"stargazers_count":119,"open_issues_count":16,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T03:07:34.478Z","etag":null,"topics":["config","configuration","configuration-management","hacktoberfest","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bnjjj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-09T22:04:44.000Z","updated_at":"2025-03-08T15:27:13.000Z","dependencies_parsed_at":"2024-10-28T12:27:24.486Z","dependency_job_id":null,"html_url":"https://github.com/bnjjj/twelf","commit_stats":{"total_commits":74,"total_committers":11,"mean_commits":"6.7272727272727275","dds":0.3648648648648649,"last_synced_commit":"cdd3b6720a1e5e6c8a28485e67d1a3de1a641c09"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjjj%2Ftwelf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjjj%2Ftwelf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjjj%2Ftwelf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjjj%2Ftwelf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnjjj","download_url":"https://codeload.github.com/bnjjj/twelf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284951,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","configuration","configuration-management","hacktoberfest","rust"],"created_at":"2024-07-31T22:02:30.380Z","updated_at":"2025-04-05T04:12:12.422Z","avatar_url":"https://github.com/bnjjj.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Twelf\n\n![Rust](https://img.shields.io/badge/rust-stable-brightgreen.svg)\n![Rust](https://github.com/bnjjj/twelf/workflows/Rust/badge.svg)\n[![Version](https://img.shields.io/crates/v/twelf.svg)](https://crates.io/crates/twelf)\n[![Docs.rs](https://docs.rs/twelf/badge.svg)](https://docs.rs/twelf)\n\n\u003e Twelf is a configuration solution for Rust including 12-Factor support. It is designed with `Layer`s in order to configure different sources and formats to build your configuration. The main goal is to be very simple using the proc macro `twelf::config`.\n\nFor now it supports :\n\n- Default settings (inside your codebase with `#[serde(default = ...)]` coming from [serde](https://serde.rs))\n- Reading from `TOML`, `YAML`, `JSON`, `DHALL`, `INI` files\n- Expanding environment variables in your configuration files, for example with a JSON file `{\"data\": ${MY_ENV_VAR:-the_default_value}}` [example](https://github.com/bnjjj/twelf/blob/master/twelf/examples/config.toml#L7)\n- Executing a custom function or closure to supply values via a [serde_json::Value]\n- Reading from environment variables: it supports `HashMap` structure with `MY_VARIABLE=\"mykey=myvalue,mykey2=myvalue2\"` and also array like `MY_VARIABLE=first,second` thanks to [envy](https://github.com/softprops/envy).\n- All [serde](https://serde.rs) attributes can be used in your struct to customize your configuration as you wish\n- Reading your configuration from your command line built with [clap](https://github.com/clap-rs/clap) (ATTENTION: if you're using version \u003c v3 use the `twelf@0.8` version)\n\n# Usage\n\n## Simple with JSON and environment variables\n\n```rust,no_run\nuse twelf::{config, Layer};\n\n#[config]\n#[derive(Default)]\nstruct Conf {\n    test: String,\n    another: usize,\n}\n\n// Init configuration with layers, each layers override only existing fields\nlet config = Conf::with_layers(\u0026[\n    Layer::Json(\"conf.json\".into()),\n    Layer::Env(Some(\"PREFIX_\".to_string()))\n]).unwrap();\n```\n\n## Example with clap support\n\n```rust,compile_fail\nuse twelf::{config, Layer};\n\n#[config]\nstruct Conf {\n    /// Here is an example of documentation which is displayed in clap\n    test: String,\n    another: usize,\n}\n\n// Will generate global arguments for each of your fields inside your configuration struct\nlet app = clap::Command::new(\"test\").args(\u0026Conf::clap_args());\n\n// Init configuration with layers, each layers override only existing fields\nlet config = Conf::with_layers(\u0026[\n    Layer::Json(\"conf.json\".into()),\n    Layer::Env(Some(\"PREFIX_\".to_string())),\n    Layer::Clap(app.get_matches().clone())\n]).unwrap();\n\n// ... your application code\n```\n\nCheck [here](./twelf/examples) for more examples.\n\n## Features\n\nTwelf supports crate features, if you only want support for `json`, `env` and `toml` then you just have to add this to your `Cargo.toml`\n\n```toml\ntwelf = { version = \"0.11\", default-features = false, features = [\"json\", \"toml\", \"env\"] }\n```\n\n`default_trait` enables code for a layer that integrate fields derived with the [std::default::Default] trait.\n\n`custom_fn` enables code for a layer that allows a custom closure to be executed.\n\nDefault features are `[\"env\", \"clap\", \"shellexpand\"]`\n\n# Contributing\n\nFeel free to contribute to the `twelf` project.\n\nEnable all features when testing changes to the crate:\n\n```console\ncargo test --all-features\n```\n\n# Alternatives\n\n- [config-rs](https://github.com/mehcode/config-rs) is almost doing the same except the environment layer (for example we support hashmap and array in environment variables). Also `config-rs` don't have clap support and it didn't use any proc-macros if you're not very fan of proc-macros.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnjjj%2Ftwelf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnjjj%2Ftwelf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnjjj%2Ftwelf/lists"}