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

Function parsePositionalFetchArgs

cli/plugins/builtin_webfetch.go:331–383  ·  view source on GitHub ↗

parsePositionalFetchArgs walks the --flag value pairs (snake_case and kebab-case accepted) starting at index start, mutating out in place. A bare http(s) token is treated as an implicit URL when none was set.

(args []string, start int, out *fetchArgs)

Source from the content-addressed store, hash-verified

329// kebab-case accepted) starting at index start, mutating out in place. A
330// bare http(s) token is treated as an implicit URL when none was set.
331func parsePositionalFetchArgs(args []string, start int, out *fetchArgs) {
332 for i := start; i < len(args); i++ {
333 a := args[i]
334 switch {
335 case a == "--url" && i+1 < len(args):
336 out.URL = args[i+1]
337 i++
338 case a == "--raw":
339 out.Raw = true
340 case a == "--max_length" || a == "--maxLength" || a == "--max-length":
341 if i+1 < len(args) {
342 _, _ = fmt.Sscanf(args[i+1], "%d", &out.MaxLength)
343 i++
344 }
345 case a == "--filter":
346 if i+1 < len(args) {
347 out.Filter = args[i+1]
348 i++
349 }
350 case a == "--exclude":
351 if i+1 < len(args) {
352 out.Exclude = args[i+1]
353 i++
354 }
355 case a == "--from_line" || a == "--from-line":
356 if i+1 < len(args) {
357 _, _ = fmt.Sscanf(args[i+1], "%d", &out.FromLine)
358 i++
359 }
360 case a == "--to_line" || a == "--to-line":
361 if i+1 < len(args) {
362 _, _ = fmt.Sscanf(args[i+1], "%d", &out.ToLine)
363 i++
364 }
365 case a == "--render":
366 out.Render = renderModeAlways
367 case a == "--no_render" || a == "--no-render":
368 out.Render = renderModeNever
369 case a == "--save_to_file" || a == "--save-to-file":
370 out.SaveToFile = true
371 case a == "--save_path" || a == "--save-path":
372 if i+1 < len(args) {
373 out.SavePath = args[i+1]
374 i++
375 }
376 default:
377 // Implicit URL as positional.
378 if out.URL == "" && strings.HasPrefix(a, "http") {
379 out.URL = a
380 }
381 }
382 }
383}
384
385func mapToFetchArgs(m map[string]interface{}, out *fetchArgs) {
386 if v, ok := m["url"].(string); ok {

Callers 1

parseFetchArgsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected