fixed arguments always resolving to empty

This commit is contained in:
Valerie Wolfe 2023-07-24 12:32:29 -04:00
parent decd6bc9a2
commit d94daca664
2 changed files with 10 additions and 8 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "config" name = "config"
version = "0.4.0" version = "0.4.1"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -50,17 +50,21 @@ fn main() -> Result<(), Box<dyn Error>>{
let mut section: &Map<String, Value> = config; let mut section: &Map<String, Value> = config;
let mut target = args.subcommand().unwrap(); let mut target = args.subcommand().unwrap();
let mut fullname = String::new(); let mut fullname = String::new();
while target.is_some() { loop {
let entry = target.unwrap().clone(); let entry = target.as_ref().unwrap();
if !fullname.is_empty() { fullname += "."; } if !fullname.is_empty() { fullname += "."; }
fullname += &entry; fullname += entry;
let i_section = section.get(&entry); let i_section = section.get(entry);
if i_section.is_none() { error::no_section(&entry); } if i_section.is_none() { error::no_section(&entry); }
section = i_section.unwrap().as_table().unwrap(); 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 // handle list flag
if args.contains(["-l", "--list"]) { if args.contains(["-l", "--list"]) {
for (key, _) in section.iter() { for (key, _) in section.iter() {
@ -69,8 +73,6 @@ fn main() -> Result<(), Box<dyn Error>>{
return Ok(()); return Ok(());
} }
if target.is_none() { error::no_args(); }
let prop_path = section.get("path"); let prop_path = section.get("path");
// handle dir flag // handle dir flag
if args.contains(["-d", "--dir"]) { if args.contains(["-d", "--dir"]) {