mirror of
https://github.com/house-of-vanity/rexec.git
synced 2025-07-06 16:44:08 +00:00
Fixed brace expansion
This commit is contained in:
2
PKGBUILD
2
PKGBUILD
@ -1,6 +1,6 @@
|
||||
# Maintainer: AB <gh@hexor.ru>
|
||||
pkgname=rexec
|
||||
pkgver=1.0.1.r9.g0d95364
|
||||
pkgver=1.0.4.r0.g3cf1e79
|
||||
pkgrel=1
|
||||
pkgdesc="Parallel SSH executor"
|
||||
url="https://github.com/house-of-vanity/rexec"
|
||||
|
41
src/main.rs
41
src/main.rs
@ -24,7 +24,11 @@ struct Args {
|
||||
#[arg(short, long, default_value_t = whoami::username())]
|
||||
username: String,
|
||||
|
||||
#[arg(short, long, help = "Use known_hosts to build servers list instead of string expansion.")]
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
help = "Use known_hosts to build servers list instead of string expansion."
|
||||
)]
|
||||
known_hosts: bool,
|
||||
|
||||
#[arg(
|
||||
@ -91,20 +95,26 @@ 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 = match r.find(']') {
|
||||
let start = r.find('[').unwrap();
|
||||
let end = match r[start..].find(']') {
|
||||
None => {
|
||||
error!("Error parsing host expression. Wrong range expansion '[a:b]'");
|
||||
process::exit(1);
|
||||
}
|
||||
Some(s) => s
|
||||
Some(s) => s + start,
|
||||
};
|
||||
let colon = r.find(':').unwrap();
|
||||
let low = r[start+1..colon].parse::<i32>().unwrap();
|
||||
let high = r[colon+1..end].parse::<i32>().unwrap();
|
||||
let colon = match r[start..end].find(':') {
|
||||
None => {
|
||||
error!("Error parsing host expression. Missing colon in range expansion '[a:b]'");
|
||||
process::exit(1);
|
||||
}
|
||||
Some(c) => c + start,
|
||||
};
|
||||
let low = r[start + 1..colon].parse::<i32>().unwrap();
|
||||
let high = r[colon + 1..end].parse::<i32>().unwrap();
|
||||
result.retain(|s| s != &r);
|
||||
for val in expand_range(low, high) {
|
||||
let new_str = format!("{}{}{}", &r[..start], val, &r[end+1..]);
|
||||
let new_str = format!("{}{}{}", &r[..start], val, &r[end + 1..]);
|
||||
result.push(new_str);
|
||||
}
|
||||
}
|
||||
@ -117,12 +127,12 @@ fn expand_string(s: &str) -> Vec<Host> {
|
||||
error!("Error parsing host expression. Wrong range expansion '{{one,two}}'");
|
||||
process::exit(1);
|
||||
}
|
||||
Some(s) => s
|
||||
Some(s) => s,
|
||||
};
|
||||
let list = &r[start+1..end];
|
||||
let list = &r[start + 1..end];
|
||||
result.retain(|s| s != &r);
|
||||
for val in expand_list(list) {
|
||||
let new_str = format!("{}{}{}", &r[..start], val, &r[end+1..]);
|
||||
let new_str = format!("{}{}{}", &r[..start], val, &r[end + 1..]);
|
||||
result.push(new_str);
|
||||
}
|
||||
}
|
||||
@ -136,7 +146,6 @@ fn expand_string(s: &str) -> Vec<Host> {
|
||||
hosts
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
|
||||
.format_timestamp(None)
|
||||
@ -172,7 +181,13 @@ fn main() {
|
||||
let mut massh_hosts: Vec<MasshHostConfig> = vec![];
|
||||
let mut hosts_and_ips: HashMap<IpAddr, String> = HashMap::new();
|
||||
if args.parallel != 100 {
|
||||
warn!("Parallelism: {} thread{}", &args.parallel, {if args.parallel != 1 {"s."} else {"."}});
|
||||
warn!("Parallelism: {} thread{}", &args.parallel, {
|
||||
if args.parallel != 1 {
|
||||
"s."
|
||||
} else {
|
||||
"."
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
info!("Matched hosts:");
|
||||
|
Reference in New Issue
Block a user