Skip to content

Commit

Permalink
fix conflict between vec of sections and subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
yaozongyou committed Oct 26, 2024
1 parent 68a44eb commit 7eb4fec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pssh-rs"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
description = "pssh-rs is a parallel ssh tool written in rust."
license-file = "LICENSE"
Expand Down
24 changes: 11 additions & 13 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct CommandLineArgs {

/// section in toml file
#[structopt(short = "s", long)]
sections: Option<Vec<String>>,
section: Option<String>,

#[structopt(subcommand)]
pub command: Command,
Expand Down Expand Up @@ -71,28 +71,26 @@ impl CommandLineArgs {
return Err(anyhow!("illegal toml format: content of toml should be a table"));
};

let Some(ref sections) = self.sections else {
let Some(ref section) = self.section else {
return get_hosts_from_table(&table);
};

if sections.is_empty() {
if section.is_empty() {
return get_hosts_from_table(&table);
}

let mut res = vec![];

for section in sections {
let Some(section_value) = table.get(section) else {
return Err(anyhow!("no {} section in the toml file", section));
};
let Some(section_value) = table.get(section) else {
return Err(anyhow!("no {} section in the toml file", section));
};

let Value::Table(section_table) = section_value else {
return Err(anyhow!("illegal section format: content of section should be a table: {}", section));
};
let Value::Table(section_table) = section_value else {
return Err(anyhow!("illegal section format: content of section should be a table: {}", section));
};

let mut hosts = get_hosts_from_table(section_table)?;
res.append(&mut hosts);
}
let mut hosts = get_hosts_from_table(section_table)?;
res.append(&mut hosts);

Ok(res)
}
Expand Down

0 comments on commit 7eb4fec

Please sign in to comment.