MCPcopy Create free account
hub / github.com/diillson/chatcli / parseGraphViewArgs

Function parseGraphViewArgs

cli/plugins/builtin_graphview.go:316–379  ·  view source on GitHub ↗

parseGraphViewArgs supports flat JSON, the {"cmd","args"} envelope and a minimal --flag argv form.

(args []string)

Source from the content-addressed store, hash-verified

314// parseGraphViewArgs supports flat JSON, the {"cmd","args"} envelope and a
315// minimal --flag argv form.
316func parseGraphViewArgs(args []string) (graphViewArgs, error) {
317 out := graphViewArgs{Source: "json", Theme: graphViewDefaultTheme()}
318 payload := strings.TrimSpace(strings.Join(args, " "))
319
320 if !strings.HasPrefix(payload, "{") {
321 // Bare argv: only the simple sources/flags are supported here.
322 if s := stringFromFlagArgs(args, []string{"source", "src"}); s != "" {
323 out.Source = s
324 }
325 if t := stringFromFlagArgs(args, []string{"theme"}); t != "" {
326 out.Theme = t
327 }
328 if o := stringFromFlagArgs(args, []string{"output", "out"}); o != "" {
329 out.Output = o
330 }
331 if f := stringFromFlagArgs(args, []string{"file"}); f != "" {
332 out.File = f
333 }
334 return finalizeGraphViewArgs(out)
335 }
336
337 var raw map[string]json.RawMessage
338 if err := json.Unmarshal([]byte(payload), &raw); err != nil {
339 return out, fmt.Errorf("malformed JSON args: %w", err)
340 }
341 if inner, ok := raw["args"]; ok {
342 var innerMap map[string]json.RawMessage
343 if err := json.Unmarshal(inner, &innerMap); err == nil {
344 raw = innerMap
345 }
346 }
347
348 if s := firstNonEmpty(jsonString(raw, "source", "src")); s != "" {
349 out.Source = s
350 }
351 out.Title = jsonString(raw, "title")
352 if t := jsonString(raw, "theme"); t != "" {
353 out.Theme = t
354 }
355 out.Output = jsonString(raw, "output", "out")
356 out.File = jsonString(raw, "file")
357 if v, ok := raw["open"]; ok {
358 var b bool
359 if json.Unmarshal(v, &b) == nil {
360 out.Open = &b
361 }
362 }
363
364 if ndata, ok := raw["nodes"]; ok {
365 var nin []gvNodeInput
366 if err := json.Unmarshal(ndata, &nin); err != nil {
367 return out, fmt.Errorf("decoding nodes: %w", err)
368 }
369 out.Nodes = normalizeNodeInputs(nin)
370 }
371 if edata, ok := raw["edges"]; ok {
372 var ein []gvEdgeInput
373 if err := json.Unmarshal(edata, &ein); err != nil {

Calls 8

graphViewDefaultThemeFunction · 0.85
stringFromFlagArgsFunction · 0.85
finalizeGraphViewArgsFunction · 0.85
jsonStringFunction · 0.85
normalizeNodeInputsFunction · 0.85
normalizeEdgeInputsFunction · 0.85
ErrorfMethod · 0.80
firstNonEmptyFunction · 0.70