mirror of
https://github.com/house-of-vanity/rexec.git
synced 2025-07-08 09:14:08 +00:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
c699bf1849 |
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rexec"
|
name = "rexec"
|
||||||
version = "1.0.3"
|
version = "1.0.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Parallel SSH executor"
|
description = "Parallel SSH executor"
|
||||||
repository = "https://github.com/house-of-vanity/rexec"
|
repository = "https://github.com/house-of-vanity/rexec"
|
||||||
|
69
src/main.rs
69
src/main.rs
@ -77,41 +77,48 @@ fn read_known_hosts() -> Vec<Host> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_range(start: i32, end: i32) -> Vec<String> {
|
fn expand_string(string: String) -> Vec<Host> {
|
||||||
(start..=end).map(|i| i.to_string()).collect()
|
let mut result: Vec<String> = Vec::new();
|
||||||
}
|
let mut _result: Vec<String> = Vec::new();
|
||||||
|
|
||||||
fn expand_list(list: &str) -> Vec<String> {
|
|
||||||
list.split(',').map(|s| s.to_string()).collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expand_string(s: &str) -> Vec<Host> {
|
|
||||||
let mut hosts: Vec<Host> = Vec::new();
|
let mut hosts: Vec<Host> = Vec::new();
|
||||||
let mut result = vec![s.to_string()];
|
|
||||||
|
|
||||||
while let Some(r) = result.iter().find(|s| s.contains('[')) {
|
if let Some(open_bracket_index) = string.find('[') {
|
||||||
let r = r.clone();
|
if let Some(close_bracket_index) = string.find(']') {
|
||||||
let start = r.find('[').unwrap();
|
let prefix = &string[..open_bracket_index];
|
||||||
let end = r.find(']').unwrap();
|
let range = &string[open_bracket_index + 1..close_bracket_index];
|
||||||
let colon = r.find(':').unwrap();
|
let postfix = &string[close_bracket_index + 1..];
|
||||||
let low = r[start + 1..colon].parse::<i32>().unwrap();
|
|
||||||
let high = r[colon + 1..end].parse::<i32>().unwrap();
|
let parts: Vec<&str> = range.split(':').collect();
|
||||||
result.retain(|s| s != &r);
|
|
||||||
for val in expand_range(low, high) {
|
if parts.len() == 2 {
|
||||||
let new_str = format!("{}{}{}", &r[..start], val, &r[end + 1..]);
|
if let Ok(start) = parts[0].parse::<u32>() {
|
||||||
result.push(new_str);
|
if let Ok(end) = parts[1].parse::<u32>() {
|
||||||
|
for num in start..=end {
|
||||||
|
_result.push(format!("{}{}{}", prefix, num, postfix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_result.push(String::from(string));
|
||||||
|
}
|
||||||
|
|
||||||
while let Some(r) = result.iter().find(|s| s.contains('{')) {
|
for string in _result {
|
||||||
let r = r.clone();
|
if let Some(open_brace_index) = string.find('{') {
|
||||||
let start = r.find('{').unwrap();
|
if let Some(close_brace_index) = string.find('}') {
|
||||||
let end = r.find('}').unwrap();
|
let prefix = &string[..open_brace_index];
|
||||||
let list = &r[start + 1..end];
|
let list = &string[open_brace_index + 1..close_brace_index];
|
||||||
result.retain(|s| s != &r);
|
let postfix = &string[close_brace_index + 1..];
|
||||||
for val in expand_list(list) {
|
|
||||||
let new_str = format!("{}{}{}", &r[..start], val, &r[end + 1..]);
|
let items: Vec<&str> = list.split(',').collect();
|
||||||
result.push(new_str);
|
|
||||||
|
for item in items {
|
||||||
|
result.push(format!("{}{}{}", prefix, item, postfix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.push(String::from(string));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +156,7 @@ fn main() {
|
|||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
info!("Using string expansion to build server list.");
|
info!("Using string expansion to build server list.");
|
||||||
expand_string(&args.expression)
|
expand_string(args.expression)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dedup hosts from known_hosts file
|
// Dedup hosts from known_hosts file
|
||||||
|
Reference in New Issue
Block a user