mirror of
https://github.com/house-of-vanity/rexec.git
synced 2025-07-06 16:44:08 +00:00
Format Rust code using rustfmt
This commit is contained in:
committed by
GitHub
parent
6dc2ab74b6
commit
c562af6f85
79
src/main.rs
79
src/main.rs
@ -146,7 +146,7 @@ fn shorten_hostname(hostname: &str, common_suffix: &Option<String>) -> String {
|
||||
Some(suffix) if hostname.ends_with(suffix) => {
|
||||
let short_name = hostname[..hostname.len() - suffix.len()].to_string();
|
||||
format!("{}{}", short_name, "*")
|
||||
},
|
||||
}
|
||||
_ => hostname.to_string(),
|
||||
}
|
||||
}
|
||||
@ -281,7 +281,13 @@ fn expand_string(s: &str) -> Vec<Host> {
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Result<i32, String>` - Exit code on success or error message
|
||||
fn execute_ssh_command(hostname: &str, username: &str, command: &str, common_suffix: &Option<String>, code_only: bool) -> Result<i32, String> {
|
||||
fn execute_ssh_command(
|
||||
hostname: &str,
|
||||
username: &str,
|
||||
command: &str,
|
||||
common_suffix: &Option<String>,
|
||||
code_only: bool,
|
||||
) -> Result<i32, String> {
|
||||
let display_name = shorten_hostname(hostname, common_suffix);
|
||||
|
||||
// Display execution start message with shortened hostname
|
||||
@ -289,8 +295,11 @@ fn execute_ssh_command(hostname: &str, username: &str, command: &str, common_suf
|
||||
|
||||
// Build the SSH command with appropriate options
|
||||
let mut ssh_cmd = Command::new("ssh");
|
||||
ssh_cmd.arg("-o").arg("StrictHostKeyChecking=no")
|
||||
.arg("-o").arg("BatchMode=yes")
|
||||
ssh_cmd
|
||||
.arg("-o")
|
||||
.arg("StrictHostKeyChecking=no")
|
||||
.arg("-o")
|
||||
.arg("BatchMode=yes")
|
||||
.arg(format!("{}@{}", username, hostname))
|
||||
.arg(command)
|
||||
.stdout(Stdio::piped())
|
||||
@ -314,9 +323,15 @@ fn execute_ssh_command(hostname: &str, username: &str, command: &str, common_suf
|
||||
match line {
|
||||
Ok(line) => {
|
||||
if !code_only_stdout {
|
||||
println!("{} {} {} {}", prefix, display_name_stdout.yellow(), prefix, line);
|
||||
println!(
|
||||
"{} {} {} {}",
|
||||
prefix,
|
||||
display_name_stdout.yellow(),
|
||||
prefix,
|
||||
line
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
@ -334,9 +349,15 @@ fn execute_ssh_command(hostname: &str, username: &str, command: &str, common_suf
|
||||
match line {
|
||||
Ok(line) => {
|
||||
if !code_only_stderr {
|
||||
println!("{} {} {} {}", prefix, display_name_stderr.yellow(), prefix, line);
|
||||
println!(
|
||||
"{} {} {} {}",
|
||||
prefix,
|
||||
display_name_stderr.yellow(),
|
||||
prefix,
|
||||
line
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
@ -361,7 +382,11 @@ fn execute_ssh_command(hostname: &str, username: &str, command: &str, common_suf
|
||||
};
|
||||
|
||||
// Display completion message
|
||||
println!("{} - COMPLETED (Exit code: [{}])", display_name.yellow().bold(), code_string);
|
||||
println!(
|
||||
"{} - COMPLETED (Exit code: [{}])",
|
||||
display_name.yellow().bold(),
|
||||
code_string
|
||||
);
|
||||
|
||||
Ok(exit_code)
|
||||
}
|
||||
@ -435,8 +460,9 @@ fn main() {
|
||||
// Results are stored with original indices to maintain order
|
||||
let resolved_ips_with_indices = Arc::new(Mutex::new(Vec::<(String, IpAddr, usize)>::new()));
|
||||
|
||||
host_with_indices.par_iter().for_each(|(host, idx)| {
|
||||
match lookup_host(&host.name) {
|
||||
host_with_indices
|
||||
.par_iter()
|
||||
.for_each(|(host, idx)| match lookup_host(&host.name) {
|
||||
Ok(ips) if !ips.is_empty() => {
|
||||
let ip = ips[0];
|
||||
let mut results = resolved_ips_with_indices.lock().unwrap();
|
||||
@ -444,12 +470,19 @@ fn main() {
|
||||
}
|
||||
Ok(_) => {
|
||||
let mut results = resolved_ips_with_indices.lock().unwrap();
|
||||
results.push((host.name.clone(), IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)), *idx));
|
||||
results.push((
|
||||
host.name.clone(),
|
||||
IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)),
|
||||
*idx,
|
||||
));
|
||||
}
|
||||
Err(_) => {
|
||||
let mut results = resolved_ips_with_indices.lock().unwrap();
|
||||
results.push((host.name.clone(), IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)), *idx));
|
||||
}
|
||||
results.push((
|
||||
host.name.clone(),
|
||||
IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0)),
|
||||
*idx,
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
@ -479,12 +512,18 @@ fn main() {
|
||||
}
|
||||
|
||||
// Find common domain suffix to optimize display
|
||||
let hostnames: Vec<String> = valid_hosts.iter().map(|(hostname, _, _)| hostname.clone()).collect();
|
||||
let hostnames: Vec<String> = valid_hosts
|
||||
.iter()
|
||||
.map(|(hostname, _, _)| hostname.clone())
|
||||
.collect();
|
||||
let common_suffix = find_common_suffix(&hostnames);
|
||||
|
||||
// Inform user about display optimization if common suffix found
|
||||
if let Some(suffix) = &common_suffix {
|
||||
info!("Common domain suffix found: '{}' (will be displayed as '*')", suffix);
|
||||
info!(
|
||||
"Common domain suffix found: '{}' (will be displayed as '*')",
|
||||
suffix
|
||||
);
|
||||
}
|
||||
|
||||
// Ask for confirmation before proceeding (unless --noconfirm is specified)
|
||||
@ -526,7 +565,13 @@ fn main() {
|
||||
|
||||
// Execute SSH command in a separate thread
|
||||
let handle = thread::spawn(move || {
|
||||
match execute_ssh_command(&hostname, &username, &command, &common_suffix_clone, code_only) {
|
||||
match execute_ssh_command(
|
||||
&hostname,
|
||||
&username,
|
||||
&command,
|
||||
&common_suffix_clone,
|
||||
code_only,
|
||||
) {
|
||||
Ok(_) => (),
|
||||
Err(e) => error!("Error executing command on {}: {}", hostname, e),
|
||||
}
|
||||
|
Reference in New Issue
Block a user