diff --git a/Cargo.toml b/Cargo.toml index aaf7a5e..beb1a8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "config" -version = "0.4.0" +version = "0.4.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 8ea450e..376b616 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,17 +50,21 @@ fn main() -> Result<(), Box>{ let mut section: &Map = config; let mut target = args.subcommand().unwrap(); let mut fullname = String::new(); - while target.is_some() { - let entry = target.unwrap().clone(); + loop { + let entry = target.as_ref().unwrap(); if !fullname.is_empty() { fullname += "."; } - fullname += &entry; - let i_section = section.get(&entry); + fullname += entry; + let i_section = section.get(entry); if i_section.is_none() { error::no_section(&entry); } section = i_section.unwrap().as_table().unwrap(); - target = args.subcommand().unwrap(); + let i_target = args.subcommand().unwrap(); + if i_target.is_none() { break; } + target = i_target; } + if target.is_none() { error::no_args(); } + // handle list flag if args.contains(["-l", "--list"]) { for (key, _) in section.iter() { @@ -69,8 +73,6 @@ fn main() -> Result<(), Box>{ return Ok(()); } - if target.is_none() { error::no_args(); } - let prop_path = section.get("path"); // handle dir flag if args.contains(["-d", "--dir"]) {