| 284 | } |
| 285 | |
| 286 | static const CommandLineCommand* FindCommandFor(const CommandLineCommand* commands, CommandLineArgEnumerator* argEnumerator) |
| 287 | { |
| 288 | // Check if end of arguments or options have started |
| 289 | const char* firstArgument; |
| 290 | if (!argEnumerator->TryPopString(&firstArgument)) |
| 291 | { |
| 292 | return commands; |
| 293 | } |
| 294 | if (firstArgument[0] == '-') |
| 295 | { |
| 296 | argEnumerator->Backtrack(); |
| 297 | return commands; |
| 298 | } |
| 299 | |
| 300 | // Search through defined commands for one that matches |
| 301 | const CommandLineCommand* fallback = nullptr; |
| 302 | const CommandLineCommand* command = commands; |
| 303 | for (; command->Name != nullptr; command++) |
| 304 | { |
| 305 | if (command->Name[0] == '\0') |
| 306 | { |
| 307 | // If we don't find a command, this should be used |
| 308 | fallback = command; |
| 309 | } |
| 310 | else if (String::equals(command->Name, firstArgument)) |
| 311 | { |
| 312 | if (command->SubCommands == nullptr) |
| 313 | { |
| 314 | // Found matching command |
| 315 | return command; |
| 316 | } |
| 317 | |
| 318 | // Recurse for the sub command table |
| 319 | return FindCommandFor(command->SubCommands, argEnumerator); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | argEnumerator->Backtrack(); |
| 324 | return fallback; |
| 325 | } |
| 326 | |
| 327 | static bool ParseOptions(const CommandLineOptionDefinition* options, CommandLineArgEnumerator* argEnumerator) |
| 328 | { |
no test coverage detected