use anyhow::Result;
use owo_colors::OwoColorize;
use std::path::Path;
use crate::executor::ParallelExecutor;
use crate::node::Node;
use crate::ssh::known_hosts::StrictHostKeyChecking;
use crate::ui::OutputFormatter;
pub async fn ping_nodes(
nodes: Vec<Node>,
max_parallel: usize,
key_path: Option<&Path>,
strict_mode: StrictHostKeyChecking,
use_agent: bool,
use_password: bool,
) -> Result<()> {
println!(
"{}",
OutputFormatter::format_command_header("ping", nodes.len())
);
let key_path = key_path.map(|p| p.to_string_lossy().to_string());
let executor = ParallelExecutor::new_with_all_options(
nodes.clone(),
max_parallel,
key_path,
strict_mode,
use_agent,
use_password,
);
let results = executor.execute("echo 'pong'").await?;
let mut success_count = 0;
let mut failed_count = 0;
println!("\n{} {}\n", "▶".cyan(), "Connection Test Results".bold());
for result in &results {
if result.is_success() {
success_count += 1;
println!(
" {} {} - {}",
"●".green(),
result.node.to_string().bold(),
"Connected".green()
);
} else {
failed_count += 1;
println!(
" {} {} - {}",
"●".red(),
result.node.to_string().bold(),
"Failed".red()
);
if let Err(e) = &result.result {
println!(" {} {}", "└".dimmed(), e.to_string().dimmed());
}
}
}
println!(
"{}",
OutputFormatter::format_summary(nodes.len(), success_count, failed_count)
);
Ok(())
}