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

Function extractStringArg

cli/plugins/args_extract.go:22–43  ·  view source on GitHub ↗

extractStringArg looks for a string value at any of the given JSON keys (in the first positional arg if it parses as JSON) and falls back to --flag style scanning across the positional args. Used by builtins to surface a single contextual value in DescribeCall without depending on the heavier per-pl

(args []string, keys ...string)

Source from the content-addressed store, hash-verified

20//
21// Keys are tried in order. Empty values are skipped.
22func extractStringArg(args []string, keys ...string) string {
23 if len(args) == 0 {
24 return ""
25 }
26 // 1. JSON in the first arg (the common case for native tool calls).
27 if v := stringFromJSONArg(args[0], keys); v != "" {
28 return v
29 }
30 // 2. --flag value across all args.
31 if v := stringFromFlagArgs(args, keys); v != "" {
32 return v
33 }
34 // 3. Whole-arg fallback for simple plugins: the first non-flag arg.
35 for _, a := range args {
36 a = strings.TrimSpace(a)
37 if a == "" || strings.HasPrefix(a, "-") || strings.HasPrefix(a, "{") || strings.HasPrefix(a, "[") {
38 continue
39 }
40 return a
41 }
42 return ""
43}
44
45// stringFromJSONArg pulls a string value out of a single JSON argument
46// blob, handling both flat formats (`{"url":"…"}`) and the nested @coder

Callers 15

DescribeCallMethod · 0.85
DescribeCallMethod · 0.85
todoSubcommandFunction · 0.85
DescribeCallMethod · 0.85
DescribeCallMethod · 0.85
DescribeCallMethod · 0.85
extractQueryArgFunction · 0.85
extractURLArgFunction · 0.85
extractPathArgFunction · 0.85
DescribeCallMethod · 0.85
coderSubcommandFunction · 0.85

Calls 2

stringFromJSONArgFunction · 0.85
stringFromFlagArgsFunction · 0.85

Tested by 1