Skip to content

Commit 938ea66

Browse files
committed
functora-cfg:0.1.1
1 parent 64f991a commit 938ea66

File tree

3 files changed

+5
-113
lines changed

3 files changed

+5
-113
lines changed

rust/functora-cfg/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/functora-cfg/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[package]
22
name = "functora-cfg"
33
license = "MIT"
4-
version = "0.1.0"
4+
version = "0.1.1"
55
edition = "2024"
66
keywords = ["config", "configuration", "settings", "env", "environment"]
77
categories = ["config"]
88
repository = "https://github.com/functora/functora.github.io/tree/master/rust/functora-cfg"
9+
documentation = "https://docs.rs/functora-cfg"
910
description = "A Rust library that merges configuration values from multiple sources into a single typed value."
1011

1112
[dependencies]
1213
clap = { version = "4.5.50", features = ["derive"] }
1314
config = "0.15.18"
14-
serde = "1.0.228"
15+
serde = { version = "1.0.228", features = ["derive"] }
1516
toml = "0.9.8"
1617

1718
[dev-dependencies]
1819
functor_derive = "0.4.3"
19-
serde = { version = "1.0.228", features = ["derive"] }
2020
serial_test = "3.2.0"
2121
temp-env = "0.3.6"
2222
tempfile = "3.23.0"

rust/functora-cfg/README.md

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,115 +7,7 @@ A Rust library that merges configuration values from multiple sources into a sin
77
- Environment variables
88
- Command-line arguments
99

10-
All sources are optional. Only the ones you provide will be applied.
11-
12-
## Example
13-
14-
```text
15-
use clap::{Parser, Subcommand};
16-
use functora_cfg;
17-
use serde::{Deserialize, Serialize};
18-
19-
#[derive(
20-
Debug, Clone, Serialize, Deserialize, PartialEq,
21-
)]
22-
pub struct Cfg {
23-
pub conn: String,
24-
pub logs: String,
25-
pub many: Vec<String>,
26-
pub nest: CfgNest,
27-
}
28-
29-
#[derive(
30-
Debug,
31-
Clone,
32-
Serialize,
33-
Deserialize,
34-
PartialEq,
35-
Subcommand,
36-
)]
37-
pub enum CfgNest {
38-
Nest { name: String, value: i32 },
39-
}
40-
41-
#[derive(Debug, Clone, Serialize, Parser)]
42-
#[command(version, about)]
43-
pub struct Cli {
44-
#[arg(long)]
45-
pub toml: Option<String>,
46-
#[arg(long)]
47-
pub conn: Option<String>,
48-
#[arg(long)]
49-
pub logs: Option<String>,
50-
#[arg(long)]
51-
pub many: Option<Vec<String>>,
52-
#[command(subcommand)]
53-
pub nest: Option<CfgNest>,
54-
}
55-
56-
fn new_cfg(cli: &Cli) -> Cfg {
57-
let defaults = Cli {
58-
toml: None,
59-
conn: Some("postgres://localhost".into()),
60-
logs: Some("/var/log/app.log".into()),
61-
many: Some(vec!["a".into(), "b".into()]),
62-
nest: Some(CfgNest::Nest {
63-
name: "foo".into(),
64-
value: 42,
65-
}),
66-
};
67-
68-
functora_cfg::Cfg {
69-
default: &defaults,
70-
file_path: |cli: &Cli| cli.toml.as_deref(),
71-
env_prefix: "FUNCTORA",
72-
command_line: cli,
73-
}
74-
.eval()
75-
.unwrap()
76-
}
77-
78-
fn main() {
79-
let cfg = new_cfg(&Cli::parse());
80-
println!("{:#?}", cfg);
81-
}
82-
```
83-
84-
Run with defaults:
85-
86-
```shell
87-
cargo run
88-
```
89-
90-
Use a config file to override defaults:
91-
92-
```shell
93-
cargo run -- --toml ./functora.toml
94-
```
95-
96-
Example `functora.toml`:
97-
98-
```toml
99-
conn = "postgres://remote"
100-
logs = "/tmp/app.log"
101-
many = ["x", "y", "z"]
102-
103-
[nest.Nest]
104-
name = "file_nested"
105-
value = 99
106-
```
107-
108-
Environment variables override defaults and file values:
109-
110-
```shell
111-
FUNCTORA_CONN="./sqlite.db" cargo run -- --toml ./functora.toml
112-
```
113-
114-
Command-line arguments override all other sources:
115-
116-
```shell
117-
cargo run -- --toml ./functora.toml --conn "./functora.db"
118-
```
10+
All sources are optional. Only the ones you provide will be applied. Here is an [example](https://github.com/functora/functora.github.io/blob/master/rust/functora-cfg/tests/integration.rs) of how to use the library.
11911

12012
<hr>
12113

0 commit comments

Comments
 (0)