* Parses flags from the given array of arguments, returning the index of the * next non-flag in the input (or the total length of the input if none are found).
(input: string[], entries: { [key: string]: string })
| 172 | * next non-flag in the input (or the total length of the input if none are found). |
| 173 | */ |
| 174 | function parseFlags(input: string[], entries: { [key: string]: string }): number { |
| 175 | // prefix with `:` to tell the library not to log anything itself |
| 176 | const parser: BasicParser = new BasicParser(`:${getOptDirective}`, input, 0); |
| 177 | |
| 178 | while (true) { |
| 179 | const next: IParsedOption | undefined = parser.getopt(); |
| 180 | if (!next) { |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | if (next.option === ':') { |
| 185 | throw new CommandParseError(`Expected flag -${next.optopt} to have an argument but it did not`); |
| 186 | } |
| 187 | |
| 188 | if (next.option === '?') { |
| 189 | throw new CommandParseError(`Unknown flag ${next.optopt}`); |
| 190 | } |
| 191 | |
| 192 | const resolver: ((entries: { [key: string]: string }, value: string) => void) | null = flags[next.option]; |
| 193 | if (!resolver) { |
| 194 | continue; // known but ignored flag |
| 195 | } |
| 196 | |
| 197 | resolver(entries, next.optarg); |
| 198 | } |
| 199 | |
| 200 | return parser.optind(); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Parses the SSH connection address. This behaves like OpenSSH and for the |
no outgoing calls
no test coverage detected