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]
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

View file

@ -50,17 +50,21 @@ fn main() -> Result<(), Box<dyn Error>>{
let mut section: &Map<String, Value> = 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<dyn Error>>{
return Ok(());
}
if target.is_none() { error::no_args(); }
let prop_path = section.get("path");
// handle dir flag
if args.contains(["-d", "--dir"]) {