| 307 | } |
| 308 | |
| 309 | void Console::Command::commandGeneric(int fd, std::string_view args) |
| 310 | { |
| 311 | // The first argument (including the empty) |
| 312 | std::string key(args); |
| 313 | auto pos = args.find(' '); |
| 314 | if ((pos != std::string::npos) && (0 < pos)) |
| 315 | { |
| 316 | key = args.substr(0, pos); |
| 317 | } |
| 318 | |
| 319 | // help |
| 320 | if (key == "help" || key == "-h") |
| 321 | { |
| 322 | commandHelp(fd, args); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | // find sub command |
| 327 | auto it = _subCommands.find(key); |
| 328 | if (it != _subCommands.end()) |
| 329 | { |
| 330 | auto subCmd = it->second; |
| 331 | if (subCmd->_callback) |
| 332 | { |
| 333 | subCmd->_callback(fd, args); |
| 334 | } |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | // can not find |
| 339 | if (_callback) |
| 340 | { |
| 341 | _callback(fd, args); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // |
| 346 | // Console code |
no test coverage detected