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
12 changes: 10 additions & 2 deletions benches/template_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,11 @@ fn bench_filter_join_opt(c: &mut Criterion) {
let template = "{{ list | join(',') }}";

group.bench_function("join_1000_items", |b| {
b.iter(|| engine.render(black_box(template), black_box(&vars)).unwrap())
b.iter(|| {
engine
.render(black_box(template), black_box(&vars))
.unwrap()
})
});

group.finish();
Expand All @@ -920,7 +924,11 @@ fn bench_filter_title_opt(c: &mut Criterion) {
let template = "{{ text | title }}";

group.bench_function("title_2000_words", |b| {
b.iter(|| engine.render(black_box(template), black_box(&vars)).unwrap())
b.iter(|| {
engine
.render(black_box(template), black_box(&vars))
.unwrap()
})
});

group.finish();
Expand Down
18 changes: 9 additions & 9 deletions src/cli/commands/drift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,8 @@ impl DriftArgs {
ctx.output.plan_header("Drift Detection Report");

ctx.output.info(&format!("Playbook: {}", report.playbook));
ctx.output.info(&format!(
"Hosts: {}",
report.hosts_checked.join(", ")
));
ctx.output
.info(&format!("Hosts: {}", report.hosts_checked.join(", ")));
ctx.output.info(&format!(
"Timestamp: {}",
report.timestamp.format("%Y-%m-%d %H:%M:%S UTC")
Expand All @@ -738,7 +736,8 @@ impl DriftArgs {
// Print resource changes if there are any drifted/missing resources
if report.summary.drifted > 0 || report.summary.missing > 0 || report.summary.extra > 0 {
println!();
ctx.output.info("Rustible will perform the following actions to remediate drift:");
ctx.output
.info("Rustible will perform the following actions to remediate drift:");
println!();

// Sort hosts for consistent output
Expand All @@ -764,7 +763,8 @@ impl DriftArgs {
}

// Print host header
ctx.output.info(&format!("# {} ({})", host, relevant_findings.len()));
ctx.output
.info(&format!("# {} ({})", host, relevant_findings.len()));
println!();

for finding in relevant_findings {
Expand Down Expand Up @@ -816,9 +816,9 @@ impl DriftArgs {

// Print Terraform-style summary
ctx.output.plan_summary(
report.summary.missing, // to_add (missing resources need to be created)
report.summary.drifted, // to_change (drifted resources need updates)
report.summary.extra, // to_destroy (extra resources should be removed)
report.summary.missing, // to_add (missing resources need to be created)
report.summary.drifted, // to_change (drifted resources need updates)
report.summary.extra, // to_destroy (extra resources should be removed)
);

// Additional statistics
Expand Down
50 changes: 27 additions & 23 deletions src/cli/commands/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ fn project_root_for_config(config_file: &Path) -> PathBuf {

#[cfg(feature = "provisioning")]
fn default_state_path(project_root: &Path) -> PathBuf {
project_root.join(".rustible").join("provisioning.state.json")
project_root
.join(".rustible")
.join("provisioning.state.json")
}

#[cfg(feature = "provisioning")]
Expand Down Expand Up @@ -841,8 +843,10 @@ impl ImportTerraformArgs {

let tf_state_json = if let Some(tfstate_path) = &self.tfstate {
if !tfstate_path.exists() {
ctx.output
.error(&format!("Terraform state not found: {}", tfstate_path.display()));
ctx.output.error(&format!(
"Terraform state not found: {}",
tfstate_path.display()
));
return Ok(1);
}
std::fs::read_to_string(tfstate_path)?
Expand Down Expand Up @@ -871,10 +875,8 @@ impl ImportTerraformArgs {
save_state(&backend_config, &state_path, &mut state).await?;

ctx.output.section("Import Successful");
ctx.output.info(&format!(
"Imported {} resources.",
state.resource_count()
));
ctx.output
.info(&format!("Imported {} resources.", state.resource_count()));
ctx.output
.info(&format!("Outputs: {}", state.outputs.len()));

Expand Down Expand Up @@ -1021,15 +1023,18 @@ outputs: {}
ctx.output
.info(&format!("Created: {}", backend_config_path.display()));
} else {
ctx.output
.info(&format!("Backend config exists: {}", backend_config_path.display()));
ctx.output.info(&format!(
"Backend config exists: {}",
backend_config_path.display()
));
}

if backend_source_provided || matches!(backend_config, BackendConfig::Local { .. }) {
match backend_config.create_backend().await {
Ok(backend) => {
if backend.exists().await? {
ctx.output.info("State already exists; skipping initialization.");
ctx.output
.info("State already exists; skipping initialization.");
} else {
let mut state = ProvisioningState::new();
state.prepare_for_save();
Expand All @@ -1038,10 +1043,8 @@ outputs: {}
}
}
Err(err) => {
ctx.output.warning(&format!(
"Skipping backend initialization: {}",
err
));
ctx.output
.warning(&format!("Skipping backend initialization: {}", err));
}
}
} else {
Expand Down Expand Up @@ -1651,12 +1654,9 @@ mod tests {

#[test]
fn test_import_terraform_args_with_tfstate() {
let cli = TestImportTerraformCli::try_parse_from([
"test",
"--tfstate",
"terraform.tfstate",
])
.unwrap();
let cli =
TestImportTerraformCli::try_parse_from(["test", "--tfstate", "terraform.tfstate"])
.unwrap();
assert_eq!(cli.args.tfstate, Some(PathBuf::from("terraform.tfstate")));
}

Expand Down Expand Up @@ -1767,9 +1767,13 @@ mod tests {

#[test]
fn test_provision_commands_import_terraform() {
let cli =
TestProvisionCli::try_parse_from(["rustible", "import-terraform", "--tfstate", "state.tfstate"])
.unwrap();
let cli = TestProvisionCli::try_parse_from([
"rustible",
"import-terraform",
"--tfstate",
"state.tfstate",
])
.unwrap();
assert!(matches!(cli.command, ProvisionCommands::ImportTerraform(_)));
}

Expand Down
91 changes: 63 additions & 28 deletions src/cli/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,11 @@ impl RunArgs {
total_tasks: 0,
},
hosts: HashMap::new(),
plan: if plan_lines.is_empty() { None } else { Some(plan_lines) },
plan: if plan_lines.is_empty() {
None
} else {
Some(plan_lines)
},
};

bundle.finish(&summary)?;
Expand Down Expand Up @@ -836,22 +840,22 @@ impl RunArgs {
ctx,
&mut plan_lines,
format!(
"{}[Play {}/{}] {} {}",
if play_idx > 0 { "\n" } else { "" },
play_idx + 1,
plays.len(),
"*".to_string(),
play_name
"{}[Play {}/{}] {} {}",
if play_idx > 0 { "\n" } else { "" },
play_idx + 1,
plays.len(),
"*".to_string(),
play_name
),
);
emit_plan_line(
ctx,
&mut plan_lines,
format!(
" Hosts: {} ({} host{})",
hosts_pattern,
hosts.len(),
if hosts.len() == 1 { "" } else { "s" }
" Hosts: {} ({} host{})",
hosts_pattern,
hosts.len(),
if hosts.len() == 1 { "" } else { "s" }
),
);

Expand Down Expand Up @@ -936,9 +940,9 @@ impl RunArgs {
ctx,
&mut plan_lines,
format!(
" Tasks: {} task{}",
total_play_tasks,
if total_play_tasks == 1 { "" } else { "s" }
" Tasks: {} task{}",
total_play_tasks,
if total_play_tasks == 1 { "" } else { "s" }
),
);

Expand Down Expand Up @@ -968,11 +972,11 @@ impl RunArgs {
ctx,
plan_lines,
format!(
"\n {} Task {}/{}: {}",
">".to_string(),
task_num,
total,
task_name
"\n {} Task {}/{}: {}",
">".to_string(),
task_num,
total,
task_name
),
);
emit_plan_line(ctx, plan_lines, format!(" Module: {}", module));
Expand All @@ -996,15 +1000,28 @@ impl RunArgs {
vec![]
};
if !handlers.is_empty() {
emit_plan_line(ctx, plan_lines, format!(" Notify: {}", handlers.join(", ")));
emit_plan_line(
ctx,
plan_lines,
format!(" Notify: {}", handlers.join(", ")),
);
}
}
};

// Show pre_tasks
for task in &pre_tasks {
task_num += 1;
show_task(ctx, &mut plan_lines, task, task_num, total_play_tasks, &hosts, &vars, self);
show_task(
ctx,
&mut plan_lines,
task,
task_num,
total_play_tasks,
&hosts,
&vars,
self,
);
}

// Show role tasks
Expand Down Expand Up @@ -1050,13 +1067,31 @@ impl RunArgs {
// Show tasks
for task in &tasks {
task_num += 1;
show_task(ctx, &mut plan_lines, task, task_num, total_play_tasks, &hosts, &vars, self);
show_task(
ctx,
&mut plan_lines,
task,
task_num,
total_play_tasks,
&hosts,
&vars,
self,
);
}

// Show post_tasks
for task in &post_tasks {
task_num += 1;
show_task(ctx, &mut plan_lines, task, task_num, total_play_tasks, &hosts, &vars, self);
show_task(
ctx,
&mut plan_lines,
task,
task_num,
total_play_tasks,
&hosts,
&vars,
self,
);
}
}

Expand Down Expand Up @@ -1145,11 +1180,11 @@ impl RunArgs {
ctx,
&mut plan_lines,
format!(
"Plan: {} task{} across {} host{}",
total_tasks,
if total_tasks == 1 { "" } else { "s" },
total_hosts.len(),
if total_hosts.len() == 1 { "" } else { "s" }
"Plan: {} task{} across {} host{}",
total_tasks,
if total_tasks == 1 { "" } else { "s" },
total_hosts.len(),
if total_hosts.len() == 1 { "" } else { "s" }
),
);

Expand Down
Loading
Loading