From a0fc361a4b3413ea99631786b4b256bb377788d5 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 30 Jul 2017 13:58:32 -0700 Subject: Rename examples/pattern -> examples/glob --- examples/glob/Cargo.toml | 7 +++++ examples/glob/conf/00-default.toml | 1 + examples/glob/conf/05-some.yml | 2 ++ examples/glob/conf/99-extra.json | 5 ++++ examples/glob/src/main.rs | 52 +++++++++++++++++++++++++++++++++++ examples/pattern/Cargo.toml | 7 ----- examples/pattern/conf/00-default.toml | 1 - examples/pattern/conf/05-some.yml | 2 -- examples/pattern/conf/99-extra.json | 5 ---- examples/pattern/src/main.rs | 52 ----------------------------------- 10 files changed, 67 insertions(+), 67 deletions(-) create mode 100644 examples/glob/Cargo.toml create mode 100644 examples/glob/conf/00-default.toml create mode 100644 examples/glob/conf/05-some.yml create mode 100644 examples/glob/conf/99-extra.json create mode 100644 examples/glob/src/main.rs delete mode 100644 examples/pattern/Cargo.toml delete mode 100644 examples/pattern/conf/00-default.toml delete mode 100644 examples/pattern/conf/05-some.yml delete mode 100644 examples/pattern/conf/99-extra.json delete mode 100644 examples/pattern/src/main.rs diff --git a/examples/glob/Cargo.toml b/examples/glob/Cargo.toml new file mode 100644 index 0000000..c4b042e --- /dev/null +++ b/examples/glob/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "glob" +version = "0.1.0" + +[dependencies] +config = { path = "../../" } +glob = "0.2" diff --git a/examples/glob/conf/00-default.toml b/examples/glob/conf/00-default.toml new file mode 100644 index 0000000..7b95e7a --- /dev/null +++ b/examples/glob/conf/00-default.toml @@ -0,0 +1 @@ +debug = false diff --git a/examples/glob/conf/05-some.yml b/examples/glob/conf/05-some.yml new file mode 100644 index 0000000..52555a0 --- /dev/null +++ b/examples/glob/conf/05-some.yml @@ -0,0 +1,2 @@ +secret: THIS IS SECRET +debug: true diff --git a/examples/glob/conf/99-extra.json b/examples/glob/conf/99-extra.json new file mode 100644 index 0000000..26f908c --- /dev/null +++ b/examples/glob/conf/99-extra.json @@ -0,0 +1,5 @@ +{ + "that": 3, + "this": 1230, + "key": "sdgnjklsdjklgds" +} diff --git a/examples/glob/src/main.rs b/examples/glob/src/main.rs new file mode 100644 index 0000000..f88f1ed --- /dev/null +++ b/examples/glob/src/main.rs @@ -0,0 +1,52 @@ +extern crate glob; +extern crate config; + +use std::path::Path; +use std::collections::HashMap; +use config::*; +use glob::glob; + +fn main() { + // Option 1 + // -------- + // Gather all conf files from conf/ manually + let mut settings = Config::default(); + settings + // File::with_name(..) is shorthand for File::from(Path::new(..)) + .merge(File::with_name("conf/00-default.toml")).unwrap() + .merge(File::from(Path::new("conf/05-some.yml"))).unwrap() + .merge(File::from(Path::new("conf/99-extra.json"))).unwrap(); + + // Print out our settings (as a HashMap) + println!("\n{:?} \n\n-----------", + settings.deserialize::>().unwrap()); + + // Option 2 + // -------- + // Gather all conf files from conf/ manually, but put in 1 merge call. + let mut settings = Config::default(); + settings + .merge(vec![File::with_name("conf/00-default.toml"), + File::from(Path::new("conf/05-some.yml")), + File::from(Path::new("conf/99-extra.json"))]) + .unwrap(); + + // Print out our settings (as a HashMap) + println!("\n{:?} \n\n-----------", + settings.deserialize::>().unwrap()); + + // Option 3 + // -------- + // Gather all conf files from conf/ using glob and put in 1 merge call. + let mut settings = Config::default(); + settings + .merge(glob("conf/*") + .unwrap() + .map(|path| File::from(path.unwrap())) + .collect::>()) + .unwrap(); + + // Print out our settings (as a HashMap) + println!("\n{:?} \n\n-----------", + settings.deserialize::>().unwrap()); +} diff --git a/examples/pattern/Cargo.toml b/examples/pattern/Cargo.toml deleted file mode 100644 index ab11750..0000000 --- a/examples/pattern/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "pattern" -version = "0.1.0" - -[dependencies] -config = { path = "../../" } -glob = "0.2" diff --git a/examples/pattern/conf/00-default.toml b/examples/pattern/conf/00-default.toml deleted file mode 100644 index 7b95e7a..0000000 --- a/examples/pattern/conf/00-default.toml +++ /dev/null @@ -1 +0,0 @@ -debug = false diff --git a/examples/pattern/conf/05-some.yml b/examples/pattern/conf/05-some.yml deleted file mode 100644 index 52555a0..0000000 --- a/examples/pattern/conf/05-some.yml +++ /dev/null @@ -1,2 +0,0 @@ -secret: THIS IS SECRET -debug: true diff --git a/examples/pattern/conf/99-extra.json b/examples/pattern/conf/99-extra.json deleted file mode 100644 index 26f908c..0000000 --- a/examples/pattern/conf/99-extra.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "that": 3, - "this": 1230, - "key": "sdgnjklsdjklgds" -} diff --git a/examples/pattern/src/main.rs b/examples/pattern/src/main.rs deleted file mode 100644 index f88f1ed..0000000 --- a/examples/pattern/src/main.rs +++ /dev/null @@ -1,52 +0,0 @@ -extern crate glob; -extern crate config; - -use std::path::Path; -use std::collections::HashMap; -use config::*; -use glob::glob; - -fn main() { - // Option 1 - // -------- - // Gather all conf files from conf/ manually - let mut settings = Config::default(); - settings - // File::with_name(..) is shorthand for File::from(Path::new(..)) - .merge(File::with_name("conf/00-default.toml")).unwrap() - .merge(File::from(Path::new("conf/05-some.yml"))).unwrap() - .merge(File::from(Path::new("conf/99-extra.json"))).unwrap(); - - // Print out our settings (as a HashMap) - println!("\n{:?} \n\n-----------", - settings.deserialize::>().unwrap()); - - // Option 2 - // -------- - // Gather all conf files from conf/ manually, but put in 1 merge call. - let mut settings = Config::default(); - settings - .merge(vec![File::with_name("conf/00-default.toml"), - File::from(Path::new("conf/05-some.yml")), - File::from(Path::new("conf/99-extra.json"))]) - .unwrap(); - - // Print out our settings (as a HashMap) - println!("\n{:?} \n\n-----------", - settings.deserialize::>().unwrap()); - - // Option 3 - // -------- - // Gather all conf files from conf/ using glob and put in 1 merge call. - let mut settings = Config::default(); - settings - .merge(glob("conf/*") - .unwrap() - .map(|path| File::from(path.unwrap())) - .collect::>()) - .unwrap(); - - // Print out our settings (as a HashMap) - println!("\n{:?} \n\n-----------", - settings.deserialize::>().unwrap()); -} -- cgit v1.2.3