| 333 | } |
| 334 | |
| 335 | bool CommandSystem::canExecute(const std::string& input) const |
| 336 | { |
| 337 | // Check the first command, ignoring arguments or subsequent commands. |
| 338 | // For now we discount the possibility that the specific arguments could |
| 339 | // change whether a command can be run, although in theory this could be possible. |
| 340 | |
| 341 | // Parsing the whole command string is rather expensive, so extract just the first token |
| 342 | CommandTokeniser tokeniser(input); |
| 343 | |
| 344 | if (tokeniser.hasMoreTokens()) |
| 345 | { |
| 346 | if (auto cmd = _commands.find(tokeniser.nextToken()); cmd != _commands.end()) |
| 347 | { |
| 348 | return cmd->second->canExecute(); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | // We only return false if we know that a command cannot run; if the command |
| 353 | // was not found at all, return true by default. |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | void CommandSystem::execute(const std::string& input) |
| 358 | { |
no test coverage detected