Skip to content

Commit 2af9c4f

Browse files
authored
fix: use parallel config value from configuration file (#18)
Previously, the parallel setting in config files was completely ignored. This fix implements proper config support for the parallel option: - Add get_parallel() method to Config struct (follows same pattern as get_timeout) - Add parallel field to ClusterDefaults struct - Check if user explicitly specified -p/--parallel in CLI args - Use config value when CLI option not explicitly provided - Priority: CLI (if explicit) > Cluster config > Global defaults > CLI default (10) Now users can set parallel in their config files: defaults: parallel: 50 clusters: production: parallel: 100 Fixes the issue where config parallel values were defined but never used.
1 parent b289462 commit 2af9c4f

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

src/config.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub struct ClusterDefaults {
133133
pub user: Option<String>,
134134
pub port: Option<u16>,
135135
pub ssh_key: Option<String>,
136+
pub parallel: Option<usize>,
136137
pub timeout: Option<u64>,
137138
}
138139

@@ -422,6 +423,18 @@ impl Config {
422423
self.defaults.timeout
423424
}
424425

426+
pub fn get_parallel(&self, cluster_name: Option<&str>) -> Option<usize> {
427+
if let Some(cluster_name) = cluster_name {
428+
if let Some(cluster) = self.get_cluster(cluster_name) {
429+
if let Some(parallel) = cluster.defaults.parallel {
430+
return Some(parallel);
431+
}
432+
}
433+
}
434+
435+
self.defaults.parallel
436+
}
437+
425438
/// Get interactive configuration for a cluster (with fallback to global)
426439
pub fn get_interactive_config(&self, cluster_name: Option<&str>) -> InteractiveConfig {
427440
let mut config = self.interactive.clone();

src/main.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ async fn main() -> Result<()> {
6666
// Initialize logging
6767
init_logging(cli.verbose);
6868

69-
// Check if user explicitly specified --config option
69+
// Check if user explicitly specified options
7070
let args: Vec<String> = std::env::args().collect();
7171
let has_explicit_config = args.iter().any(|arg| arg == "--config");
72+
let has_explicit_parallel = args.iter().any(|arg| {
73+
arg == "-p"
74+
|| arg == "--parallel"
75+
|| arg.starts_with("-p=")
76+
|| arg.starts_with("--parallel=")
77+
});
7278

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

109+
// Determine max_parallel: CLI argument takes precedence over config
110+
let max_parallel = if has_explicit_parallel {
111+
cli.parallel
112+
} else {
113+
config
114+
.get_parallel(actual_cluster_name.as_deref().or(cli.cluster.as_deref()))
115+
.unwrap_or(cli.parallel) // Fall back to CLI default (10)
116+
};
117+
103118
if nodes.is_empty() {
104119
anyhow::bail!(
105120
"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"
@@ -135,7 +150,7 @@ async fn main() -> Result<()> {
135150

136151
ping_nodes(
137152
nodes,
138-
cli.parallel,
153+
max_parallel,
139154
key_path.as_deref(),
140155
strict_mode,
141156
cli.use_agent,
@@ -159,7 +174,7 @@ async fn main() -> Result<()> {
159174

160175
let params = FileTransferParams {
161176
nodes,
162-
max_parallel: cli.parallel,
177+
max_parallel,
163178
key_path: key_path.as_deref(),
164179
strict_mode,
165180
use_agent: cli.use_agent,
@@ -184,7 +199,7 @@ async fn main() -> Result<()> {
184199

185200
let params = FileTransferParams {
186201
nodes,
187-
max_parallel: cli.parallel,
202+
max_parallel,
188203
key_path: key_path.as_deref(),
189204
strict_mode,
190205
use_agent: cli.use_agent,
@@ -293,7 +308,7 @@ async fn main() -> Result<()> {
293308
let params = ExecuteCommandParams {
294309
nodes,
295310
command: &command,
296-
max_parallel: cli.parallel,
311+
max_parallel,
297312
key_path: key_path.as_deref(),
298313
verbose: cli.verbose > 0,
299314
strict_mode,

0 commit comments

Comments
 (0)