Fix some error handling

This commit is contained in:
Alexandr Bogomyakov
2023-07-31 12:10:36 +03:00
parent ad2d36bb35
commit c635ed0dd0
3 changed files with 17 additions and 5 deletions

2
Cargo.lock generated
View File

@ -1043,7 +1043,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rexec"
version = "1.0.2"
version = "1.0.3"
dependencies = [
"brace-expand",
"clap 4.3.4",

View File

@ -1,6 +1,6 @@
[package]
name = "rexec"
version = "1.0.3"
version = "1.0.4"
edition = "2021"
description = "Parallel SSH executor"
repository = "https://github.com/house-of-vanity/rexec"

View File

@ -91,8 +91,14 @@ fn expand_string(s: &str) -> Vec<Host> {
while let Some(r) = result.iter().find(|s| s.contains('[')) {
let r = r.clone();
let start = r.find('[').unwrap();
let end = r.find(']').unwrap();
let start = r.find(']').unwrap();
let end = match r.find(']') {
None => {
error!("Error parsing host expression. Wrong range expansion '[a:b]'");
process::exit(1);
}
Some(s) => s
};
let colon = r.find(':').unwrap();
let low = r[start+1..colon].parse::<i32>().unwrap();
let high = r[colon+1..end].parse::<i32>().unwrap();
@ -106,7 +112,13 @@ fn expand_string(s: &str) -> Vec<Host> {
while let Some(r) = result.iter().find(|s| s.contains('{')) {
let r = r.clone();
let start = r.find('{').unwrap();
let end = r.find('}').unwrap();
let end = match r.find('}') {
None => {
error!("Error parsing host expression. Wrong range expansion '{{one,two}}'");
process::exit(1);
}
Some(s) => s
};
let list = &r[start+1..end];
result.retain(|s| s != &r);
for val in expand_list(list) {