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

Function parseFetchArgs

cli/plugins/builtin_webfetch.go:293–326  ·  view source on GitHub ↗

parseFetchArgs accepts either a single JSON arg or positional --flag args.

(args []string)

Source from the content-addressed store, hash-verified

291
292// parseFetchArgs accepts either a single JSON arg or positional --flag args.
293func parseFetchArgs(args []string) (fetchArgs, error) {
294 out := fetchArgs{MaxLength: defaultWebFetchMaxLength}
295
296 // Single JSON-arg form (native tool call).
297 if len(args) == 1 {
298 raw := args[0]
299 var m map[string]interface{}
300 if err := json.Unmarshal([]byte(raw), &m); err == nil {
301 // Two shapes supported:
302 // {"cmd":"fetch","args":{"url":"..."}}
303 // {"url":"...","filter":"..."}
304 if cmd, ok := m["cmd"].(string); ok && cmd == "fetch" {
305 if inner, ok := m["args"].(map[string]interface{}); ok {
306 m = inner
307 }
308 }
309 mapToFetchArgs(m, &out)
310 return out, nil
311 }
312 }
313
314 // Positional flags.
315 subcmd := args[0]
316 start := 0
317 if subcmd == "fetch" {
318 start = 1
319 } else if strings.HasPrefix(subcmd, "http") {
320 out.URL = subcmd
321 start = 1
322 }
323
324 parsePositionalFetchArgs(args, start, &out)
325 return out, nil
326}
327
328// parsePositionalFetchArgs walks the --flag value pairs (snake_case and
329// kebab-case accepted) starting at index start, mutating out in place. A

Calls 2

mapToFetchArgsFunction · 0.85
parsePositionalFetchArgsFunction · 0.85