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

Function stringFromFlagArgs

cli/plugins/args_extract.go:125–138  ·  view source on GitHub ↗

stringFromFlagArgs scans positional args for `--key value` pairs. The value may be the next arg or, after stripping quotes, embedded as `--key=value`. Returns the first match found across keys.

(args []string, keys []string)

Source from the content-addressed store, hash-verified

123// value may be the next arg or, after stripping quotes, embedded as
124// `--key=value`. Returns the first match found across keys.
125func stringFromFlagArgs(args []string, keys []string) string {
126 for _, k := range keys {
127 flag := "--" + k
128 for i, a := range args {
129 if a == flag && i+1 < len(args) {
130 return trimQuotes(args[i+1])
131 }
132 if strings.HasPrefix(a, flag+"=") {
133 return trimQuotes(strings.TrimPrefix(a, flag+"="))
134 }
135 }
136 }
137 return ""
138}
139
140// trimQuotes strips a single matching pair of surrounding ASCII quotes.
141func trimQuotes(s string) string {

Callers 4

parseGraphViewArgsFunction · 0.85
parseWikipediaArgsFunction · 0.85
extractStringArgFunction · 0.85
extractNestedArgFunction · 0.85

Calls 1

trimQuotesFunction · 0.85

Tested by

no test coverage detected