scsictl shall accept generic key/value pairs for options that take parameters (#1240) (#1274)

* scsictl accepts generic key/value pairs for options that take parameters
This commit is contained in:
Uwe Seimet
2023-10-31 09:02:28 +01:00
committed by GitHub
parent 8bd06ea5cd
commit 7bbcf59c76
4 changed files with 43 additions and 4 deletions
+22 -1
View File
@@ -42,8 +42,12 @@ void protobuf_util::ParseParameters(PbDeviceDefinition& device, const string& pa
}
}
void protobuf_util::SetCommandParams(PbCommand& command, const string& params)
string protobuf_util::SetCommandParams(PbCommand& command, const string& params)
{
if (params.find(KEY_VALUE_SEPARATOR) != string::npos) {
return SetFromGenericParams(command, params);
}
string folder_pattern;
string file_pattern;
string operations;
@@ -69,6 +73,23 @@ void protobuf_util::SetCommandParams(PbCommand& command, const string& params)
SetParam(command, "folder_pattern", folder_pattern);
SetParam(command, "file_pattern", file_pattern);
SetParam(command, "operations", operations);
return "";
}
string protobuf_util::SetFromGenericParams(PbCommand& command, const string& params)
{
for (const string& key_value : Split(params, COMPONENT_SEPARATOR)) {
const auto& param = Split(key_value, KEY_VALUE_SEPARATOR, 2);
if (param.size() > 1 && !param[0].empty()) {
SetParam(command, param[0], param[1]);
}
else {
return "Parameter '" + key_value + "' has to be a key/value pair";
}
}
return "";
}
void protobuf_util::SetProductData(PbDeviceDefinition& device, const string& data)