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

Function jsonInt

cli/plugins/args_extract.go:101–120  ·  view source on GitHub ↗

jsonInt mirrors jsonString for integer fields. Tries each alias, returns the first parseable int. Strings that contain a valid int (e.g. "10") are coerced — the LLM occasionally emits stringified numbers and we don't want to reject those.

(raw map[string]json.RawMessage, keys ...string)

Source from the content-addressed store, hash-verified

99// (e.g. "10") are coerced — the LLM occasionally emits stringified
100// numbers and we don't want to reject those.
101func jsonInt(raw map[string]json.RawMessage, keys ...string) int {
102 for _, k := range keys {
103 val, ok := raw[k]
104 if !ok {
105 continue
106 }
107 var n int
108 if err := json.Unmarshal(val, &n); err == nil {
109 return n
110 }
111 // Fallback: stringified integer.
112 var s string
113 if err := json.Unmarshal(val, &s); err == nil {
114 if parsed, perr := strconv.Atoi(strings.TrimSpace(s)); perr == nil {
115 return parsed
116 }
117 }
118 }
119 return 0
120}
121
122// stringFromFlagArgs scans positional args for `--key value` pairs. The
123// value may be the next arg or, after stripping quotes, embedded as

Callers 11

parseDocsFlattenArgsFunction · 0.85
parseDiagramArgsFunction · 0.85
ExecuteWithStreamMethod · 0.85
parseSearchArgsFunction · 0.85
TestContextArgvFormFunction · 0.85
parseReadArgsFunction · 0.85
parseRegistryTagsArgsFunction · 0.85
ExecuteWithStreamMethod · 0.85
contextRagTopKFunction · 0.85
parseTreeArgsFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestContextArgvFormFunction · 0.68