@@ -24,10 +24,14 @@ pub enum SyncCmd {
2424
2525 /// Export sync event log
2626 Events ( SyncEventsArgs ) ,
27+
28+ /// Show computed sync partners for this library
29+ Partners ,
2730}
2831
2932pub async fn run ( ctx : & Context , cmd : SyncCmd ) -> Result < ( ) > {
3033 match cmd {
34+ SyncCmd :: Partners => show_partners ( ctx) . await ?,
3135 SyncCmd :: Events ( args) => export_events ( ctx, args) . await ?,
3236 SyncCmd :: Metrics ( args) => {
3337 // Parse time filters
@@ -590,3 +594,95 @@ fn format_events_markdown(
590594
591595 output
592596}
597+
598+ async fn show_partners ( ctx : & Context ) -> Result < ( ) > {
599+ let library_id = ctx. library_id . ok_or_else ( || {
600+ anyhow:: anyhow!( "No library selected. Use 'sd library switch' to select a library first." )
601+ } ) ?;
602+
603+ // Create input for the operation
604+ let input = sd_core:: ops:: sync:: get_sync_partners:: GetSyncPartnersInput { } ;
605+
606+ let json_response = ctx. core . query ( & input, Some ( library_id) ) . await ?;
607+ let output: sd_core:: ops:: sync:: get_sync_partners:: GetSyncPartnersOutput =
608+ serde_json:: from_value ( json_response) ?;
609+
610+ println ! ( "\n {}" , "Sync Partners for Current Library" . bold( ) ) ;
611+ println ! ( "{}" , "═" . repeat( 60 ) ) ;
612+ println ! ( ) ;
613+
614+ if output. partners . is_empty ( ) {
615+ println ! ( " {} No connected sync partners found" , "●" . red( ) ) ;
616+ println ! ( ) ;
617+ println ! ( " Possible reasons:" ) ;
618+ println ! ( " - No other devices paired with this device" ) ;
619+ println ! ( " - Paired devices are not in this library's devices table" ) ;
620+ println ! ( " - Paired devices do not have sync_enabled=true" ) ;
621+ println ! ( ) ;
622+ } else {
623+ println ! ( " {} {} sync partner(s) available" , "●" . green( ) , output. partners. len( ) ) ;
624+ println ! ( ) ;
625+
626+ let mut table = Table :: new ( ) ;
627+ table
628+ . load_preset ( UTF8_FULL )
629+ . set_content_arrangement ( ContentArrangement :: Dynamic )
630+ . set_header ( Row :: from ( vec ! [
631+ Cell :: new( "Device UUID" ) . add_attribute( Attribute :: Bold ) ,
632+ Cell :: new( "Name" ) . add_attribute( Attribute :: Bold ) ,
633+ Cell :: new( "Status" ) . add_attribute( Attribute :: Bold ) ,
634+ ] ) ) ;
635+
636+ for partner in & output. partners {
637+ table. add_row ( vec ! [
638+ partner. device_uuid. to_string( ) ,
639+ partner. device_name. clone( ) ,
640+ if partner. is_paired {
641+ "✓ Paired" . green( ) . to_string( )
642+ } else {
643+ "○ Not Paired" . dark_grey( ) . to_string( )
644+ } ,
645+ ] ) ;
646+ }
647+
648+ println ! ( "{}" , table) ;
649+ println ! ( ) ;
650+ }
651+
652+ // Show debug info
653+ println ! ( "{}" , "Library Membership Debug" . dark_grey( ) . bold( ) ) ;
654+ println ! ( "{}" , "─" . repeat( 60 ) . dark_grey( ) ) ;
655+ println ! ( ) ;
656+ println ! ( " Total devices in library: {}" , output. debug_info. total_devices) ;
657+ println ! ( " Devices with sync_enabled: {}" , output. debug_info. sync_enabled_devices) ;
658+ println ! ( " Devices with NodeId mapping: {}" , output. debug_info. paired_devices) ;
659+ println ! ( " Final sync partners: {}" , output. debug_info. final_sync_partners) ;
660+ println ! ( ) ;
661+
662+ if !output. debug_info . device_details . is_empty ( ) {
663+ let mut debug_table = Table :: new ( ) ;
664+ debug_table
665+ . load_preset ( UTF8_FULL )
666+ . set_content_arrangement ( ContentArrangement :: Dynamic )
667+ . set_header ( Row :: from ( vec ! [
668+ Cell :: new( "Device" ) . add_attribute( Attribute :: Bold ) . fg( Color :: DarkGrey ) ,
669+ Cell :: new( "Sync Enabled" ) . add_attribute( Attribute :: Bold ) . fg( Color :: DarkGrey ) ,
670+ Cell :: new( "Has NodeId" ) . add_attribute( Attribute :: Bold ) . fg( Color :: DarkGrey ) ,
671+ Cell :: new( "NodeId" ) . add_attribute( Attribute :: Bold ) . fg( Color :: DarkGrey ) ,
672+ ] ) ) ;
673+
674+ for device in & output. debug_info . device_details {
675+ debug_table. add_row ( vec ! [
676+ Cell :: new( & device. name) . fg( Color :: DarkGrey ) ,
677+ Cell :: new( if device. sync_enabled { "✓" } else { "✗" } ) . fg( Color :: DarkGrey ) ,
678+ Cell :: new( if device. has_node_id { "✓" } else { "✗" } ) . fg( Color :: DarkGrey ) ,
679+ Cell :: new( device. node_id. as_deref( ) . unwrap_or( "-" ) ) . fg( Color :: DarkGrey ) ,
680+ ] ) ;
681+ }
682+
683+ println ! ( "{}" , debug_table) ;
684+ println ! ( ) ;
685+ }
686+
687+ Ok ( ( ) )
688+ }
0 commit comments