diff --git a/examples/files/simple.toml b/examples/files/simple.toml index a3e5e4f..5a2f43a 100644 --- a/examples/files/simple.toml +++ b/examples/files/simple.toml @@ -1,2 +1,2 @@ -[cat] -foo = "yes" +[log] +stdout = false diff --git a/examples/simple.rs b/examples/simple.rs index 9f2181b..8ed4fec 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,40 +1,53 @@ -use std::{net::IpAddr, path::Path}; -use confique::Config; +use std::{net::IpAddr, path::{Path, PathBuf}}; +use confique::{Config, toml::FormatOptions}; #[derive(Debug, Config)] +/// A sample configuration for our app. struct Conf { #[config(nested)] http: Http, #[config(nested)] - cat: Cat, + log: LogConfig, } - +/// Configuring the HTTP server of our app. #[derive(Debug, Config)] struct Http { - #[config(default = 8080)] + /// The port the server will listen on. port: u16, + /// The bind address of the server. Can be set to `0.0.0.0` for example, to + /// allow other users of the network to access the server. #[config(default = "127.0.0.1")] bind: IpAddr, } #[derive(Debug, Config)] -struct Cat { - foo: Option, +struct LogConfig { + /// If set to `true`, the app will log to stdout. + #[config(default = true)] + stdout: bool, + + /// If this is set, the app will write logs to the given file. Of course, + /// the app has to have write access to that file. + file: Option, } fn main() -> Result<(), anyhow::Error> { - println!("{:#?}", Conf::META); + println!("TEMPLATE:"); + println!("--------------------------------------------------------"); + print!("{}", confique::toml::format::(FormatOptions::default())); + println!("--------------------------------------------------------"); let r = Conf::from_sources(&[ &Path::new("examples/files/simple.toml"), &Path::new("examples/files/etc/simple.yaml"), ])?; - println!("{:#?}", r); + println!(); + println!("LOADED CONFIGURATION: {:#?}", r); Ok(()) }