{"id":15022131,"url":"https://github.com/abakay/irx-config","last_synced_at":"2025-04-12T06:12:50.272Z","repository":{"id":38850290,"uuid":"442041770","full_name":"abakay/irx-config","owner":"abakay","description":"The library provides convenient way to represent/parse configuration from different sources. The main goals is to be very easy to use and to be extendable","archived":false,"fork":false,"pushed_at":"2024-11-14T03:10:20.000Z","size":89,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T06:12:41.172Z","etag":null,"topics":["clap","command-line","config","configuration","environment","environment-variables","json","json5","parsers","rust","seal","secrets","toml","yaml"],"latest_commit_sha":null,"homepage":"https://docs.rs/irx-config/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abakay.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-12-27T03:41:16.000Z","updated_at":"2024-11-14T03:08:22.000Z","dependencies_parsed_at":"2023-12-14T08:46:41.128Z","dependency_job_id":null,"html_url":"https://github.com/abakay/irx-config","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"64fca55066e801673505538ca75ec911bced01e6"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abakay%2Firx-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abakay%2Firx-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abakay%2Firx-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abakay%2Firx-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abakay","download_url":"https://codeload.github.com/abakay/irx-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525138,"owners_count":21118619,"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":["clap","command-line","config","configuration","environment","environment-variables","json","json5","parsers","rust","seal","secrets","toml","yaml"],"created_at":"2024-09-24T19:57:30.203Z","updated_at":"2025-04-12T06:12:50.255Z","avatar_url":"https://github.com/abakay.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# irx-config library\n\n![GitHub top language](https://img.shields.io/github/languages/top/abakay/irx-config) ![Crates.io](https://img.shields.io/crates/v/irx-config) ![Crates.io](https://img.shields.io/crates/l/irx-config) ![Crates.io](https://img.shields.io/crates/d/irx-config) ![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/cargo/irx-config) ![docs.rs](https://img.shields.io/docsrs/irx-config) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/abakay/irx-config/rust.yml)\n\nThe `irx-config` library provides convenient way to represent/parse configuration from different sources. The main\ngoals is to be very easy to use and to be extendable.\n\n## Features\n\n* Fully compatible with [serde](https://serde.rs/)\n* Full deep merge of nested dictionaries/mappings\n* Case sensitive/insensitive parameters names matching/merging\n* Sealing secrets during display/debugging\n* Get all configuration parameters or just cherry pick few\n* Several embedded parsers available via library features:\n  * Command-line argument (via [clap](https://github.com/clap-rs/clap))\n  * Environment variables\n  * File based parsers: `JSON`, `JSON5`, `YAML` and `TOML`\n* Could be extended with custom parsers\n\n## Examples\n\n### JSON with environment variables\n\nTo enable parsers used in example below, one has to add the following to `Cargo.toml`:\n\n```toml\n[dependencies]\nirx-config = { version = \"3.5\", features = [\"env\", \"json\"] }\n```\n\n```rust\nuse irx_config::parsers::{env, json};\nuse irx_config::ConfigBuilder;\nuse serde::Deserialize;\n\n#[derive(Deserialize)]\nstruct Conf {\n    id: u32,\n    logger: String,\n    tag: String,\n}\n\n// Data from two parsers will be merged. The values from parser appended first (`JSON`)\n// will take precedence if values have a same names\nlet config = ConfigBuilder::default()\n    .append_parser(\n        json::ParserBuilder::default()\n            .default_path(\"config.json\")\n            .build()?,\n    )\n    .append_parser(\n        env::ParserBuilder::default()\n            .default_prefix(\"APP_\")\n            .build()?,\n    )\n    .load()?;\n\nlet conf_data: Conf = config.get()?;\n```\n\n### Command-line, TOML and environment variables\n\nTo enable parsers used in example below, one has to add the following to `Cargo.toml`:\n\n```toml\n[dependencies]\nirx-config = { version = \"3.5\", features = [\"cmd\", \"env\", \"toml-parser\"] }\n```\n\n```rust\nuse clap::app_from_crate;\nuse irx_config::parsers::{cmd, env, toml};\nuse irx_config::ConfigBuilder;\nuse serde::Deserialize;\n\nfn localhost() -\u003e String {\n    \"localhost\".into()\n}\n\n#[derive(Deserialize)]\nstruct Logger {\n    level: String,\n    path: String,\n}\n\n#[derive(Deserialize)]\nstruct Connection {\n    #[serde(default = \"localhost\")]\n    host: String,\n    port: u16,\n}\n\n#[derive(Deserialize)]\nstruct Conf {\n    id: u32,\n    logger: Logger,\n    connection: Connection,\n}\n\nlet app = app_from_crate!();\n\n// Data from three parsers will be merged. The values from parser appended first (`cmd`)\n// will take precedence if values have a same names\nlet config = ConfigBuilder::default()\n    .append_parser(\n        cmd::ParserBuilder::new(app)\n            .exit_on_error(true)\n            .build()?,\n    )\n    .append_parser(\n        toml::ParserBuilder::default()\n            .default_path(\"config.toml\")\n            .path_option(\"config\")\n            .build()?,\n    )\n    .append_parser(\n        env::ParserBuilder::default()\n            .default_prefix(\"APP_\")\n            .prefix_option(\"prefix\")\n            .build()?,\n    )\n    .load()?;\n\nlet conf_data: Conf = config.get()?;\n```\n\n### Custom parser\n\n```rust\nuse irx_config::{AnyResult, Case, ConfigBuilder, Parse, Value};\nuse serde::Deserialize;\nuse std::borrow::Cow;\n\n#[derive(Deserialize)]\nstruct Conf {\n    id: u32,\n    logger: String,\n    tag: String,\n}\n\nstruct JsonStringParser\u003c'a\u003e {\n    data: Cow\u003c'a, str\u003e,\n}\n\nimpl\u003c'a\u003e JsonStringParser\u003c'a\u003e {\n    pub fn new(data: impl Into\u003cCow\u003c'a, str\u003e\u003e) -\u003e Self {\n        JsonStringParser { data: data.into() }\n    }\n}\n\nimpl Case for JsonStringParser\u003c'_\u003e {}\n\nimpl Parse for JsonStringParser\u003c'_\u003e {\n    fn parse(\u0026mut self, _value: \u0026Value) -\u003e AnyResult\u003cValue\u003e {\n        Ok(serde_json::from_str(\u0026self.data)?)\n    }\n}\n\nlet data = r#\"{ \"id\": 42, \"logger\": \"file\", \"tag\": \"test\" }\"#;\nlet config = ConfigBuilder::load_one(JsonStringParser::new(data))?;\nlet conf_data: Conf = config.get()?;\n```\n\n### JSON parser get partial data\n\nTo enable parsers used in example below, one has to add the following to `Cargo.toml`:\n\n```toml\n[dependencies]\nirx-config = { version = \"3.5\", features = [\"json\"] }\n```\n\n```rust\nuse irx_config::parsers::json;\nuse irx_config::ConfigBuilder;\nuse serde::Deserialize;\n\nfn localhost() -\u003e String {\n    \"localhost\".into()\n}\n\n#[derive(Deserialize)]\nstruct Logger {\n    level: String,\n    path: String,\n}\n\n#[derive(Deserialize)]\nstruct Connection {\n    #[serde(default = \"localhost\")]\n    host: String,\n    port: u16,\n}\n\nlet config = ConfigBuilder::load_one(\n    json::ParserBuilder::default()\n        .default_path(\"config.json\")\n        .build()?,\n)?;\n\nlet logger: Logger = config.get_by_key_path(\"logger\")?.unwrap();\nlet port: u16 = config.get_by_key_path(\"connection:port\")?.unwrap();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabakay%2Firx-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabakay%2Firx-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabakay%2Firx-config/lists"}