Skip to content

Commit 0e81559

Browse files
Implement progress reporting for more 'shovels' commands
1 parent f80ffab commit 0e81559

File tree

4 files changed

+75
-65
lines changed

4 files changed

+75
-65
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## v2.14.0 (in development)
44

5-
No changes yet.
5+
### Enhancements
66

7+
* Several commands now have minimalistic progress indicators: `federation disable_tls_peer_verification_for_all_upstreams`, `federation enable_tls_peer_verification_for_all_upstreams`, `shovels disable_tls_peer_verification_for_all_source_uris`, `shovels disable_tls_peer_verification_for_all_destination_uris`, `shovels enable_tls_peer_verification_for_all_source_uris`, and `shovels enable_tls_peer_verification_for_all_destination_uris`
78

89
## v2.13.0 (Sep 26, 2025)
910

src/commands.rs

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ pub fn disable_tls_peer_verification_for_all_federation_upstreams(
744744
prog_rep.report_success(upstream_name);
745745
}
746746

747-
prog_rep.finish_operation(total, total);
747+
prog_rep.finish_operation(total);
748748

749749
Ok(())
750750
}
@@ -825,7 +825,7 @@ pub fn enable_tls_peer_verification_for_all_federation_upstreams(
825825
prog_rep.report_success(upstream_name);
826826
}
827827

828-
prog_rep.finish_operation(total, total);
828+
prog_rep.finish_operation(total);
829829
Ok(())
830830
}
831831

@@ -849,7 +849,7 @@ pub fn disable_tls_peer_verification_for_all_source_uris(
849849
let owned_params = match OwnedShovelParams::try_from(param.clone()) {
850850
Ok(params) => params,
851851
Err(_) => {
852-
prog_rep.report_skip(param_name, "invalid shovel parameters");
852+
prog_rep.report_skip(param_name, "shovel parameters fail validation");
853853
continue;
854854
}
855855
};
@@ -871,51 +871,62 @@ pub fn disable_tls_peer_verification_for_all_source_uris(
871871
prog_rep.report_success(param_name);
872872
}
873873

874-
prog_rep.finish_operation(total, total);
874+
prog_rep.finish_operation(total);
875875

876876
Ok(())
877877
}
878878

879879
pub fn disable_tls_peer_verification_for_all_destination_uris(
880880
client: APIClient,
881-
_prog_rep: &mut dyn ProgressReporter,
881+
prog_rep: &mut dyn ProgressReporter,
882882
) -> Result<(), CommandRunError> {
883883
let all_params = client.list_runtime_parameters()?;
884884
let shovel_params: Vec<_> = all_params
885885
.into_iter()
886886
.filter(|p| p.component == "shovel")
887887
.collect();
888888

889-
for param in shovel_params {
889+
let total = shovel_params.len();
890+
prog_rep.start_operation(total, "Updating shovel destination URIs");
891+
892+
for (index, param) in shovel_params.into_iter().enumerate() {
893+
let param_name = &param.name;
894+
prog_rep.report_progress(index + 1, total, param_name);
895+
890896
let owned_params = match OwnedShovelParams::try_from(param.clone()) {
891897
Ok(params) => params,
892-
Err(_) => continue,
898+
Err(_) => {
899+
prog_rep.report_skip(param_name, "shovel parameters fail validation");
900+
continue;
901+
}
893902
};
894903

895904
let original_destination_uri = &owned_params.destination_uri;
896905

897906
if original_destination_uri.is_empty() {
907+
prog_rep.report_skip(param_name, "empty destination URI");
898908
continue;
899909
}
900910

901911
let updated_destination_uri = disable_tls_peer_verification(original_destination_uri)?;
902912

903-
if original_destination_uri != &updated_destination_uri {
904-
let mut updated_params = owned_params;
905-
updated_params.destination_uri = updated_destination_uri;
913+
let mut updated_params = owned_params;
914+
updated_params.destination_uri = updated_destination_uri;
906915

907-
let param = RuntimeParameterDefinition::from(&updated_params);
908-
client.upsert_runtime_parameter(&param)?;
909-
}
916+
let param = RuntimeParameterDefinition::from(&updated_params);
917+
client.upsert_runtime_parameter(&param)?;
918+
prog_rep.report_success(param_name);
910919
}
911920

921+
prog_rep.finish_operation(total);
922+
912923
Ok(())
913924
}
914925

915926
pub fn enable_tls_peer_verification_for_all_source_uris(
916927
client: APIClient,
917928
args: &ArgMatches,
918-
_prog_rep: &mut dyn ProgressReporter,
929+
prog_rep: &mut dyn ProgressReporter,
919930
) -> Result<(), CommandRunError> {
920931
let ca_cert_path = args
921932
.get_one::<String>("node_local_ca_certificate_bundle_path")
@@ -939,14 +950,24 @@ pub fn enable_tls_peer_verification_for_all_source_uris(
939950
.filter(|p| p.component == "shovel")
940951
.collect();
941952

942-
for param in shovel_params {
953+
let total = shovel_params.len();
954+
prog_rep.start_operation(total, "Updating shovel source URIs");
955+
956+
for (index, param) in shovel_params.into_iter().enumerate() {
957+
let param_name = &param.name;
958+
prog_rep.report_progress(index + 1, total, param_name);
959+
943960
let owned_params = match OwnedShovelParams::try_from(param.clone()) {
944961
Ok(params) => params,
945-
Err(_) => continue,
962+
Err(_) => {
963+
prog_rep.report_skip(param_name, "shovel parameters fail validation");
964+
continue;
965+
}
946966
};
947967

948968
let original_source_uri = &owned_params.source_uri;
949969
if original_source_uri.is_empty() {
970+
prog_rep.report_skip(param_name, "empty source URI");
950971
continue;
951972
}
952973

@@ -957,22 +978,23 @@ pub fn enable_tls_peer_verification_for_all_source_uris(
957978
client_key_path,
958979
)?;
959980

960-
if original_source_uri != &updated_source_uri {
961-
let mut updated_params = owned_params;
962-
updated_params.source_uri = updated_source_uri;
981+
let mut updated_params = owned_params;
982+
updated_params.source_uri = updated_source_uri;
963983

964-
let param = RuntimeParameterDefinition::from(&updated_params);
965-
client.upsert_runtime_parameter(&param)?;
966-
}
984+
let param = RuntimeParameterDefinition::from(&updated_params);
985+
client.upsert_runtime_parameter(&param)?;
986+
prog_rep.report_success(param_name);
967987
}
968988

989+
prog_rep.finish_operation(total);
990+
969991
Ok(())
970992
}
971993

972994
pub fn enable_tls_peer_verification_for_all_destination_uris(
973995
client: APIClient,
974996
args: &ArgMatches,
975-
_prog_rep: &mut dyn ProgressReporter,
997+
prog_rep: &mut dyn ProgressReporter,
976998
) -> Result<(), CommandRunError> {
977999
let ca_cert_path = args
9781000
.get_one::<String>("node_local_ca_certificate_bundle_path")
@@ -996,14 +1018,24 @@ pub fn enable_tls_peer_verification_for_all_destination_uris(
9961018
.filter(|p| p.component == "shovel")
9971019
.collect();
9981020

999-
for param in shovel_params {
1021+
let total = shovel_params.len();
1022+
prog_rep.start_operation(total, "Updating shovel destination URIs");
1023+
1024+
for (index, param) in shovel_params.into_iter().enumerate() {
1025+
let param_name = &param.name;
1026+
prog_rep.report_progress(index + 1, total, param_name);
1027+
10001028
let owned_params = match OwnedShovelParams::try_from(param.clone()) {
10011029
Ok(params) => params,
1002-
Err(_) => continue,
1030+
Err(_) => {
1031+
prog_rep.report_skip(param_name, "shovel parameters fail validation");
1032+
continue;
1033+
}
10031034
};
10041035

10051036
let original_destination_uri = &owned_params.destination_uri;
10061037
if original_destination_uri.is_empty() {
1038+
prog_rep.report_skip(param_name, "empty destination URI");
10071039
continue;
10081040
}
10091041

@@ -1014,15 +1046,16 @@ pub fn enable_tls_peer_verification_for_all_destination_uris(
10141046
client_key_path,
10151047
)?;
10161048

1017-
if original_destination_uri != &updated_destination_uri {
1018-
let mut updated_params = owned_params;
1019-
updated_params.destination_uri = updated_destination_uri;
1049+
let mut updated_params = owned_params;
1050+
updated_params.destination_uri = updated_destination_uri;
10201051

1021-
let param = RuntimeParameterDefinition::from(&updated_params);
1022-
client.upsert_runtime_parameter(&param)?;
1023-
}
1052+
let param = RuntimeParameterDefinition::from(&updated_params);
1053+
client.upsert_runtime_parameter(&param)?;
1054+
prog_rep.report_success(param_name);
10241055
}
10251056

1057+
prog_rep.finish_operation(total);
1058+
10261059
Ok(())
10271060
}
10281061

src/output.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ pub trait ProgressReporter {
461461
fn report_progress(&mut self, current: usize, total: usize, item_name: &str);
462462
fn report_success(&mut self, item_name: &str);
463463
fn report_skip(&mut self, item_name: &str, reason: &str);
464-
fn finish_operation(&mut self, succeeded: usize, total: usize);
464+
fn finish_operation(&mut self, total: usize);
465465
}
466466

467467
#[allow(dead_code)]
@@ -502,23 +502,15 @@ impl ProgressReporter for InteractiveProgressReporter {
502502
}
503503

504504
fn report_success(&mut self, _item_name: &str) {
505-
print!(" ✅");
505+
// No-op: progress bar already shows the advancement
506506
}
507507

508508
fn report_skip(&mut self, _item_name: &str, _reason: &str) {
509509
// No-op: progress bar already shows the advancement
510510
}
511511

512-
fn finish_operation(&mut self, succeeded: usize, total: usize) {
513-
let skipped = total - succeeded;
514-
if skipped > 0 {
515-
println!(
516-
"\n✓ Completed: {} updated, {} already configured",
517-
succeeded, skipped
518-
);
519-
} else {
520-
println!("\n✓ Completed: {} items updated", succeeded);
521-
}
512+
fn finish_operation(&mut self, total: usize) {
513+
println!("\n✅ Completed: {} items processed", total);
522514
}
523515
}
524516

@@ -556,16 +548,8 @@ impl ProgressReporter for NonInteractiveProgressReporter {
556548
// Dot already printed in report_progress
557549
}
558550

559-
fn finish_operation(&mut self, succeeded: usize, total: usize) {
560-
let skipped = total - succeeded;
561-
if skipped > 0 {
562-
println!(
563-
"\nCompleted: {} updated, {} already configured",
564-
succeeded, skipped
565-
);
566-
} else {
567-
println!("\nCompleted: {} items updated", succeeded);
568-
}
551+
fn finish_operation(&mut self, total: usize) {
552+
println!("\nCompleted: {} items processed", total);
569553
}
570554
}
571555

@@ -596,15 +580,7 @@ impl ProgressReporter for QuietProgressReporter {
596580
// Silent
597581
}
598582

599-
fn finish_operation(&mut self, succeeded: usize, total: usize) {
600-
let skipped = total - succeeded;
601-
if skipped > 0 {
602-
println!(
603-
"Completed: {} updated, {} already configured",
604-
succeeded, skipped
605-
);
606-
} else {
607-
println!("Completed: {} items updated", succeeded);
608-
}
583+
fn finish_operation(&mut self, total: usize) {
584+
println!("Completed: {} items processed", total);
609585
}
610586
}

tests/interactivity_mode_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn test_interactivity_mode_non_interactive() {
2929

3030
#[test]
3131
fn test_interactivity_mode_from_env_interactive() {
32-
// Clear the environment variable to test default case
32+
// Clear the environment variable to test the default case
3333
unsafe {
3434
std::env::remove_var("RABBITMQADMIN_NON_INTERACTIVE_MODE");
3535
}

0 commit comments

Comments
 (0)