| 42 | } |
| 43 | |
| 44 | QString ValidCommand(QJsonObject extJsonObject, bool* result) |
| 45 | { |
| 46 | QRegularExpression regex(R"((\w+)\s+([\[\<][^\s\]]+[\s\w-]*[\>\]])(\s*\([^\)]*\))?(?:\s+\{(.+)\})?)"); |
| 47 | |
| 48 | if( !extJsonObject.contains("command") || !extJsonObject["command"].isString() ) { |
| 49 | *result = false; |
| 50 | return "Extension must include a required 'command' parameter"; |
| 51 | } |
| 52 | QString command = extJsonObject["command"].toString(); |
| 53 | |
| 54 | if (extJsonObject.contains("subcommands")) { |
| 55 | QJsonArray subcommandArray = extJsonObject["subcommands"].toArray(); |
| 56 | for (QJsonValue subCmdVal : subcommandArray) { |
| 57 | QJsonObject subCmdObj = subCmdVal.toObject(); |
| 58 | |
| 59 | if( !subCmdObj.contains("name") || !subCmdObj["name"].isString() ) { |
| 60 | *result = false; |
| 61 | return QString("The command '%1' does not contain a 'name' parameter in Subcommand block").arg(command); |
| 62 | } |
| 63 | QString subcommand = subCmdObj["name"].toString(); |
| 64 | |
| 65 | QJsonArray subArgsArray = subCmdObj["args"].toArray(); |
| 66 | for (QJsonValue subArgVal : subArgsArray) { |
| 67 | QRegularExpressionMatch match = regex.match( subArgVal.toString() ); |
| 68 | if ( !match.hasMatch()) { |
| 69 | *result = false; |
| 70 | return "Arguments not parsed for command: " + command + " " + subcommand; |
| 71 | } |
| 72 | |
| 73 | QString flagAndValue = match.captured(2).trimmed(); |
| 74 | if (!((flagAndValue.startsWith('<') && flagAndValue.endsWith('>')) || (flagAndValue.startsWith('[') && flagAndValue.endsWith(']')))) { |
| 75 | *result = false; |
| 76 | return "Argument must be in <> or [] for command: " + command + " " + subcommand; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } else { |
| 81 | if (extJsonObject.contains("args")) { |
| 82 | QJsonArray argsArray = extJsonObject["args"].toArray(); |
| 83 | for (QJsonValue argVal : argsArray) { |
| 84 | QRegularExpressionMatch match = regex.match( argVal.toString() ); |
| 85 | if ( !match.hasMatch()) { |
| 86 | *result = false; |
| 87 | return "Arguments not parsed for command: " + command; |
| 88 | } |
| 89 | |
| 90 | QString flagAndValue = match.captured(2).trimmed(); |
| 91 | if (!((flagAndValue.startsWith('<') && flagAndValue.endsWith('>')) || (flagAndValue.startsWith('[') && flagAndValue.endsWith(']')))) { |
| 92 | *result = false; |
| 93 | return "Argument must be in <> or [] for command: " + command; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | return ""; |
| 99 | } |
| 100 | |
| 101 | QString ValidExtCommand(QJsonObject extJsonObject, bool* result) |
no test coverage detected