Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion guide/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This crate provides the following features:
- **cmd** - A command-line argument configuration source
- **json** - A \*.json file configuration source
- **xml** - A \*.xml file configuration source
- **yaml** - A \*.yaml file configuration source
- **ini** - An \*.ini file configuration source
- **chained** - Chain multiple configuration sources
- **binder** - Bind a configuration to strongly-typed values and structs
Expand All @@ -31,4 +32,4 @@ a [pull request](https://github.com/commonsensesoftware/more-rs-config/pulls).

## License

This project is licensed under the [MIT](https://github.com/commonsensesoftware/more-rs-config/blob/main/LICENSE) license.
This project is licensed under the [MIT](https://github.com/commonsensesoftware/more-rs-config/blob/main/LICENSE) license.
3 changes: 2 additions & 1 deletion guide/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Command-Line Provider](guide/cmd.md)
- [JSON Provider](guide/json.md)
- [XML Provider](guide/xml.md)
- [YAML Provider](guide/yaml.md)
- [INI Provider](guide/ini.md)
- [Chained Provider](guide/chained.md)
- [Data Binding](guide/binding.md)
- [Data Binding](guide/binding.md)
1 change: 1 addition & 0 deletions guide/src/guide/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ REF: https://github.com/tag1consulting/goose/issues/320

[`JsonConfigurationProvider`]: https://docs.rs/more-config/2.0.0/config/struct.JsonConfigurationProvider.html
[`XmlConfigurationProvider`]: https://docs.rs/more-config/2.0.0/config/struct.XmlConfigurationProvider.html
[`YamlConfigurationProvider`]: https://docs.rs/more-config/2.0.0/config/struct.YamlConfigurationProvider.html
[`IniConfigurationProvider`]: https://docs.rs/more-config/2.0.0/config/struct.IniConfigurationProvider.html
[`MemoryConfigurationProvider`]: https://docs.rs/more-config/2.0.0/config/struct.MemoryConfigurationProvider.html
48 changes: 48 additions & 0 deletions guide/src/guide/yaml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{#include links.md}}

# YAML Configuration Provider

>These features are only available if the **yaml** feature is activated

The [`YamlConfigurationProvider`] supports loading configuration from a `*.yaml` file.

Consider the following `appsettings.yaml` file:

```yaml
Position:
Title: Editor
Name: Joe Smith
MyKey: My appsettings.yaml Value
Logging:
LogLevel:
Default: Information
App: Warning
App.Hosting.Lifetime: Information
AllowedHosts: "*"
```

The following code displays several of the preceding configurations settings:

```rust
use config::{*, ext::*};

fn main() {
let config = DefaultConfigurationBuilder::new()
.add_yaml_file("appsettings.yaml")
.build()
.unwrap();

let my_key_value = config.get("MyKey").unwrap().as_str();
let title = config.get("Position:Title").unwrap().as_str();
let name = config.section("Position").get("Name").unwrap().as_str();
let default_log_level = config.get("Logging:LogLevel:Default").unwrap().as_str();

println!("MyKey value: {}\n\
Title: {}\n\
Name: {}\n\
Default Log Level: {}",
my_key_value,
title,
name,
default_log_level);
}
30 changes: 27 additions & 3 deletions src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ include = ["*.rs", "!build.rs", "README.md"]

# RUSTDOCFLAGS="--cfg docsrs"; cargo +nightly doc
[package.metadata.docs.rs]
features = ["std", "chained", "mem", "env", "cmd", "ini", "json", "xml", "binder"]
features = [
"std",
"chained",
"mem",
"env",
"cmd",
"ini",
"json",
"xml",
"yaml",
"binder",
]
rustdoc-args = ["--cfg", "docsrs"]

[lib]
Expand All @@ -34,14 +45,27 @@ cmd = ["util"]
ini = ["util", "dep:configparser", "more-changetoken/fs"]
binder = ["dep:serde"]
json = ["util", "dep:serde_json", "more-changetoken/fs"]
yaml = ["util", "dep:serde_yaml", "more-changetoken/fs"]
xml = ["util", "dep:xml_rs", "more-changetoken/fs"]
all = ["std", "chained", "mem", "env", "cmd", "ini", "binder", "json", "xml"]
all = [
"std",
"chained",
"mem",
"env",
"cmd",
"ini",
"binder",
"json",
"xml",
"yaml",
]

[dependencies]
more-changetoken = "2.0"
configparser = { version = "3.0", optional = true }
serde = { version = "1.0", optional = true }
serde_json = { version = "1.0", optional = true }
serde_yaml = { version = "0.9", optional = true }
xml_rs = { version = "0.8", package = "xml", optional = true }
cfg-if = "1.0"

Expand All @@ -50,4 +74,4 @@ test-case = "2.2"

[dev-dependencies.more-config]
path = "."
features = ["cmd", "json"]
features = ["cmd", "json"]
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ mod cmd;
#[cfg(feature = "xml")]
mod xml;

#[cfg(feature = "yaml")]
mod yaml;

#[cfg(feature = "binder")]
mod binder;

Expand Down Expand Up @@ -97,6 +100,10 @@ pub use cmd::{CommandLineConfigurationProvider, CommandLineConfigurationSource};
#[cfg_attr(docsrs, doc(cfg(feature = "xml")))]
pub use xml::{XmlConfigurationProvider, XmlConfigurationSource};

#[cfg(feature = "yaml")]
#[cfg_attr(docsrs, doc(cfg(feature = "yaml")))]
pub use yaml::{YamlConfigurationProvider, YamlConfigurationSource};

/// Contains configuration extension methods.
pub mod ext {

Expand Down Expand Up @@ -130,6 +137,10 @@ pub mod ext {
#[cfg_attr(docsrs, doc(cfg(feature = "xml")))]
pub use super::xml::ext::*;

#[cfg(feature = "yaml")]
#[cfg_attr(docsrs, doc(cfg(feature = "yaml")))]
pub use yaml::ext::*;

#[cfg(feature = "binder")]
#[cfg_attr(docsrs, doc(cfg(feature = "binder")))]
pub use binder::*;
Expand All @@ -138,6 +149,6 @@ pub mod ext {
#[cfg_attr(docsrs, doc(cfg(feature = "binder")))]
pub use de::*;

pub use section::ext::*;
pub use file::ext::*;
pub use section::ext::*;
}
9 changes: 2 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::{min, Ordering};
use std::collections::HashMap;
use std::fmt::{Formatter, Result as FormatResult, Write};

#[cfg(feature = "json")]
#[cfg(any(feature = "json", feature = "yaml"))]
pub(crate) fn to_pascal_case<T: AsRef<str>>(text: T) -> String {
let mut chars = text.as_ref().chars();

Expand Down Expand Up @@ -167,12 +167,7 @@ fn recurse_children<T: ConfigurationRoot>(

formatter.write_char('\n')?;

recurse_children(
root,
&child.children(),
formatter,
&(indent.to_owned() + " "),
)?;
recurse_children(root, &child.children(), formatter, &(indent.to_owned() + " "))?;
}

Ok(())
Expand Down
Loading