fixed list flag not properly using sections

This commit is contained in:
Valerie Wolfe 2022-06-27 19:57:50 -04:00
parent bc015a169d
commit c78bbf21c3
3 changed files with 17 additions and 5 deletions

2
Cargo.lock generated
View file

@ -4,7 +4,7 @@ version = 3
[[package]]
name = "config"
version = "0.0.1"
version = "0.1.0"
dependencies = [
"toml",
]

View file

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

View file

@ -15,7 +15,7 @@ use toml::Value;
mod error;
pub const VERSION: &str = "0.0.2";
pub const VERSION: &str = "0.1.0";
fn main() -> Result<(), Box<dyn Error>>{
let home_dir = var("HOME").unwrap();
@ -58,7 +58,19 @@ fn main() -> Result<(), Box<dyn Error>>{
}
if list {
for key in config.keys() {
let mut section = config;
if args.len() > 1 {
let mut args = args.clone();
args.remove(0);
for arg in args {
let i_sub = section.get(arg.as_str());
if i_sub.is_none() { return Ok(()); }
let sub = i_sub.unwrap().as_table();
if sub.is_none() { return Ok(()); }
section = sub.unwrap();
}
}
for key in section.keys() {
println!("{}", key);
}
return Ok(());
@ -145,7 +157,7 @@ fn main() -> Result<(), Box<dyn Error>>{
fn help_text() {
println!("config v{}", VERSION);
println!("Valerie Wolfe <sleeplessval@gmail.com");
println!("Valerie Wolfe <sleeplessval@gmail.com>");
println!("A configuration manager written in Rust.\n");
println!("USAGE:");
println!("\tconfig NAME\n");