allow extending existing vars

This commit is contained in:
John
2024-10-02 07:02:31 +02:00
parent 1511db2e27
commit eebb2ef3f5
2 changed files with 8 additions and 9 deletions
+2 -1
View File
@@ -71,7 +71,8 @@ static const argDef g_mqtt_argDefs[] = {
{"mqttretain", O_RETA, nullptr, 0, "Retain all topics instead of only selected global ones"},
{"mqttqos", O_PQOS, "QOS", 0, "Set the QoS value for all topics (0-2) [0]"},
{"mqttint", O_INTF, "FILE", 0, "Read MQTT integration settings from FILE (no default)"},
{"mqttvar", O_IVAR, "NAME=VALUE[,...]", 0, "Add variable(s) to the read MQTT integration settings"},
{"mqttvar", O_IVAR, "NAME[+]=VALUE[,...]", 0, "Add variable(s) to the read MQTT integration settings "
"(append to already existing value with \"NAME+=VALUE\")"},
{"mqttjson", O_JSON, "short", af_optional,
"Publish in JSON format instead of strings, optionally in short (value directly below field key)"},
{"mqttverbose", O_VERB, nullptr, 0, "Publish all available attributes"},
+6 -8
View File
@@ -373,16 +373,14 @@ void StringReplacers::parseLine(const string& line) {
if (pos == string::npos || pos == 0) {
return;
}
bool emptyIfMissing = false;
string key;
if (line[pos-1] == '?') {
emptyIfMissing = true;
key = line.substr(0, pos-1);
} else {
key = line.substr(0, pos);
}
bool emptyIfMissing = line[pos-1] == '?';
bool append = !emptyIfMissing && line[pos-1] == '+';
string key = line.substr(0, (emptyIfMissing || append) ? pos-1 : pos);
FileReader::trim(&key);
string value = line.substr(pos+1);
if (append) {
value = get(key).str() + value;
}
FileReader::trim(&value);
if (value.find('%') == string::npos) {
set(key, value); // constant value