blocksListRun implements the 'blocks list' command It retrieves and displays blocks with optional filtering by workspace, window, tab, or view type
(cmd *cobra.Command, args []string)
| 98 | // blocksListRun implements the 'blocks list' command |
| 99 | // It retrieves and displays blocks with optional filtering by workspace, window, tab, or view type |
| 100 | func blocksListRun(cmd *cobra.Command, args []string) error { |
| 101 | if v := strings.TrimSpace(blocksView); v != "" { |
| 102 | if !isKnownViewFilter(v) { |
| 103 | return fmt.Errorf("unknown --view %q; try one of: term, web, preview, edit, sysinfo, waveai", v) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | var allBlocks []BlockDetails |
| 108 | |
| 109 | workspaces, err := wshclient.WorkspaceListCommand(RpcClient, &wshrpc.RpcOpts{Timeout: int64(blocksTimeout)}) |
| 110 | if err != nil { |
| 111 | return fmt.Errorf("failed to list workspaces: %v", err) |
| 112 | } |
| 113 | |
| 114 | if len(workspaces) == 0 { |
| 115 | return fmt.Errorf("no workspaces found") |
| 116 | } |
| 117 | |
| 118 | var workspaceIdsToQuery []string |
| 119 | |
| 120 | // Determine which workspaces to query |
| 121 | if blocksWorkspaceId != "" && blocksWindowId != "" { |
| 122 | return fmt.Errorf("--workspace and --window are mutually exclusive; specify only one") |
| 123 | } |
| 124 | if blocksWorkspaceId != "" { |
| 125 | workspaceIdsToQuery = []string{blocksWorkspaceId} |
| 126 | } else if blocksWindowId != "" { |
| 127 | // Find workspace ID for this window |
| 128 | windowFound := false |
| 129 | for _, ws := range workspaces { |
| 130 | if ws.WindowId == blocksWindowId { |
| 131 | workspaceIdsToQuery = []string{ws.WorkspaceData.OID} |
| 132 | windowFound = true |
| 133 | break |
| 134 | } |
| 135 | } |
| 136 | if !windowFound { |
| 137 | return fmt.Errorf("window %s not found", blocksWindowId) |
| 138 | } |
| 139 | } else { |
| 140 | // Default to all workspaces |
| 141 | for _, ws := range workspaces { |
| 142 | workspaceIdsToQuery = append(workspaceIdsToQuery, ws.WorkspaceData.OID) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Query each selected workspace |
| 147 | hadSuccess := false |
| 148 | for _, wsId := range workspaceIdsToQuery { |
| 149 | req := wshrpc.BlocksListRequest{WorkspaceId: wsId} |
| 150 | if blocksWindowId != "" { |
| 151 | req.WindowId = blocksWindowId |
| 152 | } |
| 153 | |
| 154 | blocks, err := wshclient.BlocksListCommand(RpcClient, req, &wshrpc.RpcOpts{Timeout: int64(blocksTimeout)}) |
| 155 | if err != nil { |
| 156 | WriteStderr("Warning: couldn't list blocks for workspace %s: %v\n", wsId, err) |
| 157 | continue |
nothing calls this directly
no test coverage detected