Skip to content

Commit

Permalink
refactor: refactored config parser code, no more use of deprecated fu…
Browse files Browse the repository at this point in the history
…nctions
  • Loading branch information
gh0st42 committed Nov 22, 2023
1 parent e6db102 commit 732d1a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
9 changes: 7 additions & 2 deletions core/dtn7/src/dtnconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,18 @@ pub fn rnd_node_name() -> String {
impl From<PathBuf> for DtnConfig {
fn from(item: PathBuf) -> Self {
let mut dtncfg = DtnConfig::new();
let mut s = Config::default();
let s_default = Config::default();

let configbuilder = Config::builder().add_source(s_default);

debug!("Loading config: {}", item.to_str().unwrap());

// Start off by merging in the "default" configuration file
s.merge(File::new(item.to_str().unwrap(), config::FileFormat::Toml))
let s = configbuilder
.add_source(File::new(item.to_str().unwrap(), config::FileFormat::Toml))
.build()
.unwrap();

dtncfg.debug = s.get_bool("debug").unwrap_or(false);
if dtncfg.debug {
//std::env::set_var("RUST_LOG", "dtn7=debug,dtnd=debug");
Expand Down
16 changes: 9 additions & 7 deletions core/dtn7/tests/config-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ use config::{Config, File};

#[test]
fn config_test() {
let mut s = Config::default();

// Start off by merging in the "default" configuration file
s.merge(File::new(
"../../examples/dtn7.toml.example",
config::FileFormat::Toml,
))
.unwrap();
let s = Config::builder()
.add_source(Config::default())
.add_source(File::new(
"../../examples/dtn7.toml.example",
config::FileFormat::Toml,
))
.build()
.unwrap();

println!("{:?}", s);

println!("debug: {:?}", s.get_bool("debug").unwrap_or(false));
Expand Down

0 comments on commit 732d1a0

Please sign in to comment.