MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / blocksListRun

Function blocksListRun

cmd/wsh/cmd/wshcmd-blocks.go:100–256  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

98// blocksListRun implements the 'blocks list' command
99// It retrieves and displays blocks with optional filtering by workspace, window, tab, or view type
100func 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

Callers

nothing calls this directly

Calls 8

WorkspaceListCommandFunction · 0.92
BlocksListCommandFunction · 0.92
isKnownViewFilterFunction · 0.85
WriteStderrFunction · 0.85
matchesViewTypeFunction · 0.85
WriteStdoutFunction · 0.85
GetStringMethod · 0.80
FlushMethod · 0.65

Tested by

no test coverage detected