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)
| 123 | // value may be the next arg or, after stripping quotes, embedded as |
| 124 | // `--key=value`. Returns the first match found across keys. |
| 125 | func 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. |
| 141 | func trimQuotes(s string) string { |
no test coverage detected