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

Method ExecuteWithStream

cli/plugins/builtin_graphview.go:200–236  ·  view source on GitHub ↗

ExecuteWithStream resolves the data source, writes the HTML and opens it.

(_ context.Context, args []string, _ func(string))

Source from the content-addressed store, hash-verified

198
199// ExecuteWithStream resolves the data source, writes the HTML and opens it.
200func (p *BuiltinGraphViewPlugin) ExecuteWithStream(_ context.Context, args []string, _ func(string)) (string, error) {
201 cfg, err := parseGraphViewArgs(args)
202 if err != nil {
203 return "", fmt.Errorf("@graphview: %w", err)
204 }
205
206 data, err := resolveGraphData(cfg)
207 if err != nil {
208 return "", fmt.Errorf("@graphview: %w", err)
209 }
210 if len(data.Nodes) == 0 {
211 return i18n.T("plugins.graphview.empty"), nil
212 }
213 if len(data.Nodes) > graphViewMaxNodes {
214 return "", fmt.Errorf("@graphview: %s", i18n.T("plugins.graphview.too_big", len(data.Nodes), graphViewMaxNodes))
215 }
216
217 path, err := renderGraphViewHTML(data, cfg.Output)
218 if err != nil {
219 return "", fmt.Errorf("@graphview: %w", err)
220 }
221
222 opened := false
223 if cfg.shouldOpen() {
224 if oerr := openInBrowser(path); oerr == nil {
225 opened = true
226 }
227 }
228
229 msg := i18n.T("plugins.graphview.rendered", path, len(data.Nodes), len(data.Edges))
230 if opened {
231 msg += "\n" + i18n.T("plugins.graphview.opened")
232 } else {
233 msg += "\n" + i18n.T("plugins.graphview.open_hint", path)
234 }
235 return msg, nil
236}
237
238// graphViewArgs is the typed view of @graphview's input.
239type graphViewArgs struct {

Callers 1

ExecuteMethod · 0.95

Calls 7

TFunction · 0.92
parseGraphViewArgsFunction · 0.85
resolveGraphDataFunction · 0.85
renderGraphViewHTMLFunction · 0.85
openInBrowserFunction · 0.85
ErrorfMethod · 0.80
shouldOpenMethod · 0.80

Tested by

no test coverage detected