Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ pub struct ClusterDefaults {
pub user: Option<String>,
pub port: Option<u16>,
pub ssh_key: Option<String>,
pub parallel: Option<usize>,
pub timeout: Option<u64>,
}

Expand Down Expand Up @@ -422,6 +423,18 @@ impl Config {
self.defaults.timeout
}

pub fn get_parallel(&self, cluster_name: Option<&str>) -> Option<usize> {
if let Some(cluster_name) = cluster_name {
if let Some(cluster) = self.get_cluster(cluster_name) {
if let Some(parallel) = cluster.defaults.parallel {
return Some(parallel);
}
}
}

self.defaults.parallel
}

/// Get interactive configuration for a cluster (with fallback to global)
pub fn get_interactive_config(&self, cluster_name: Option<&str>) -> InteractiveConfig {
let mut config = self.interactive.clone();
Expand Down
25 changes: 20 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ async fn main() -> Result<()> {
// Initialize logging
init_logging(cli.verbose);

// Check if user explicitly specified --config option
// Check if user explicitly specified options
let args: Vec<String> = std::env::args().collect();
let has_explicit_config = args.iter().any(|arg| arg == "--config");
let has_explicit_parallel = args.iter().any(|arg| {
arg == "-p"
|| arg == "--parallel"
|| arg.starts_with("-p=")
|| arg.starts_with("--parallel=")
});

// If user explicitly specified --config, ensure the file exists
if has_explicit_config {
Expand Down Expand Up @@ -100,6 +106,15 @@ async fn main() -> Result<()> {
// Determine nodes to execute on
let (nodes, actual_cluster_name) = resolve_nodes(&cli, &config).await?;

// Determine max_parallel: CLI argument takes precedence over config
let max_parallel = if has_explicit_parallel {
cli.parallel
} else {
config
.get_parallel(actual_cluster_name.as_deref().or(cli.cluster.as_deref()))
.unwrap_or(cli.parallel) // Fall back to CLI default (10)
};

if nodes.is_empty() {
anyhow::bail!(
"No hosts specified. Please use one of the following options:\n -H <hosts> Specify comma-separated hosts (e.g., -H user@host1,user@host2)\n -c <cluster> Use a cluster from your configuration file"
Expand Down Expand Up @@ -135,7 +150,7 @@ async fn main() -> Result<()> {

ping_nodes(
nodes,
cli.parallel,
max_parallel,
key_path.as_deref(),
strict_mode,
cli.use_agent,
Expand All @@ -159,7 +174,7 @@ async fn main() -> Result<()> {

let params = FileTransferParams {
nodes,
max_parallel: cli.parallel,
max_parallel,
key_path: key_path.as_deref(),
strict_mode,
use_agent: cli.use_agent,
Expand All @@ -184,7 +199,7 @@ async fn main() -> Result<()> {

let params = FileTransferParams {
nodes,
max_parallel: cli.parallel,
max_parallel,
key_path: key_path.as_deref(),
strict_mode,
use_agent: cli.use_agent,
Expand Down Expand Up @@ -293,7 +308,7 @@ async fn main() -> Result<()> {
let params = ExecuteCommandParams {
nodes,
command: &command,
max_parallel: cli.parallel,
max_parallel,
key_path: key_path.as_deref(),
verbose: cli.verbose > 0,
strict_mode,
Expand Down