parseWorkspaceListJSON decodes the JSON shape `pad workspace list --format json` emits into the WorkspaceHint slice. Lenient about optional fields — only `slug` is required; everything else gets zero values when absent.
(body string)
| 314 | // optional fields — only `slug` is required; everything else gets |
| 315 | // zero values when absent. |
| 316 | func parseWorkspaceListJSON(body string) ([]WorkspaceHint, error) { |
| 317 | body = strings.TrimSpace(body) |
| 318 | if body == "" || body == "null" { |
| 319 | return nil, nil |
| 320 | } |
| 321 | var raw []map[string]any |
| 322 | if err := json.Unmarshal([]byte(body), &raw); err != nil { |
| 323 | return nil, fmt.Errorf("decode workspace list: %w", err) |
| 324 | } |
| 325 | out := make([]WorkspaceHint, 0, len(raw)) |
| 326 | for _, w := range raw { |
| 327 | slug, _ := w["slug"].(string) |
| 328 | if slug == "" { |
| 329 | continue |
| 330 | } |
| 331 | name, _ := w["name"].(string) |
| 332 | isDefault, _ := w["default"].(bool) |
| 333 | out = append(out, WorkspaceHint{Slug: slug, Name: name, Default: isDefault}) |
| 334 | } |
| 335 | return out, nil |
| 336 | } |
| 337 | |
| 338 | // BuildCLIArgs translates an MCP tool call's JSON arguments into the |
| 339 | // CLI argument list that should be appended after the command path. |
no outgoing calls