@@ -84,23 +84,35 @@ async fn run(args: Args) -> Result<(), BridgeError> {
8484 } => {
8585 let topics = kafka_connection. topics . clone ( ) ;
8686 let client: KafkaBridgeClient = kafka_connection. into ( ) ;
87- trace ! ( "applying target offsets" ) ;
88- let snapshot = OffsetSnapshot :: from_csv ( input) ?;
8987
90- // Handle confirmation in CLI before calling the core library
91- if !dry_run && !skip_confirmation && !ask_for_confirmation ( & snapshot) {
92- return Err ( BridgeError :: Message (
93- "Operation cancelled by user" . to_string ( ) ,
88+ let snapshot = {
89+ let snapshot = OffsetSnapshot :: from_csv ( input) ?;
90+ snapshot. filter_by_topics ( & topics)
91+ } ;
92+
93+ if snapshot. is_empty ( ) {
94+ // TODO decouple from command error
95+ return Err ( BridgeError :: ApplyOffsets (
96+ bridge_core:: commands:: apply_target_offsets:: errors:: ApplyOffsetsError :: NoOffsetsToApply ,
9497 ) ) ;
9598 }
9699
97- if dry_run {
98- println ! ( "DRY RUN: Would apply the following offsets:" ) ;
99- print_offset_snapshot ( & snapshot) ;
100- Ok ( ( ) )
101- } else {
102- client. apply_target_offsets ( topics, snapshot, false ) . await
100+ // Only show confirmation/dry-run output if snapshot has data
101+ // (core library validates if offsets remain after topic filtering)
102+ if !snapshot. is_empty ( ) {
103+ if !dry_run && !skip_confirmation && !ask_for_confirmation ( & snapshot) {
104+ return Err ( BridgeError :: Message (
105+ "Operation cancelled by user" . to_string ( ) ,
106+ ) ) ;
107+ }
108+
109+ if dry_run {
110+ eprintln ! ( "DRY RUN: Would apply the following offsets:" ) ;
111+ print_offset_snapshot ( & snapshot) ;
112+ }
103113 }
114+
115+ client. apply_target_offsets ( topics, snapshot, dry_run) . await
104116 }
105117 }
106118}
0 commit comments