fix list subcommand

Signed-off-by: Dmytro Stanchiev <git@dmytros.dev>
This commit is contained in:
2025-10-31 11:43:45 -04:00
parent d10efaff7b
commit b52a48a0d8
3 changed files with 21 additions and 5 deletions

2
Cargo.lock generated
View File

@@ -180,7 +180,7 @@ checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
[[package]] [[package]]
name = "moshy" name = "moshy"
version = "0.1.1" version = "0.1.2"
dependencies = [ dependencies = [
"clap", "clap",
"env_logger", "env_logger",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "moshy" name = "moshy"
version = "0.1.1" version = "0.1.2"
edition = "2024" edition = "2024"
[dependencies] [dependencies]

View File

@@ -84,9 +84,23 @@ fn main() {
if let Some(list_matches) = matches.subcommand_matches("list") { if let Some(list_matches) = matches.subcommand_matches("list") {
let sections: Vec<String> = conf let sections: Vec<String> = conf
.sections() .sections()
.filter_map(|s| s.map(|x| x.to_string())) .filter_map(|s| s)
.filter(|s| *s != "DEFAULT")
.map(|s| s.to_string())
.collect(); .collect();
if list_matches.is_present("verbose") {
for section in &sections {
println!("[{}]", section);
if let Some(sec) = conf.section(Some(section)) {
for (k, v) in sec.iter() {
println!("{} = {}", k, v);
}
}
println!();
}
} else {
println!("{}", sections.join("\n")); println!("{}", sections.join("\n"));
}
process::exit(0); process::exit(0);
} }
@@ -174,7 +188,9 @@ fn parse_hostname(hostname_argument: &str, conf: &Ini) -> HostSetup {
let sections: Vec<String> = conf let sections: Vec<String> = conf
.sections() .sections()
.filter_map(|s| s.map(|x| x.to_string())) .filter_map(|s| s)
.filter(|s| *s != "DEFAULT")
.map(|s| s.to_string())
.collect(); .collect();
debug!("Config sections: {:?}", sections); debug!("Config sections: {:?}", sections);