Update and fix JSON writer (#183)

* Fixing the check of createKey in handleConfigSetCommand

* Update schema-config.json

* add overwrite option to configset command

* add overwrite option to setConfig function

* add overwrite option to setConfig function
This commit is contained in:
Paulchen-Panther 2016-08-18 21:11:21 +02:00 committed by redPanther
parent e46d392ed1
commit b9ad2977de
5 changed files with 11 additions and 5 deletions

View File

@ -931,8 +931,9 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message, co
return;
}
bool createKey = message.isMember("create");
Json::Value hyperionConfig = _hyperion->getJsonConfig();
bool createKey = message["create"].asBool();
Json::Value hyperionConfig;
message["overwrite"].asBool() ? createKey = true : hyperionConfig = _hyperion->getJsonConfig();
nested::configSetCommand(message["config"], hyperionConfig, createKey);
JsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfig);

View File

@ -20,6 +20,9 @@
},
"create": {
"type" : "boolean"
},
"overwrite": {
"type" : "boolean"
}
},
"additionalProperties": false

View File

@ -268,7 +268,7 @@ QString JsonConnection::getConfig(std::string type)
return QString();
}
void JsonConnection::setConfig(const std::string &jsonString, bool create)
void JsonConnection::setConfig(const std::string &jsonString, bool create, bool overwrite)
{
// create command
Json::Value command;
@ -276,6 +276,7 @@ void JsonConnection::setConfig(const std::string &jsonString, bool create)
command["subcommand"] = "setconfig";
command["create"] = create;
command["overwrite"] = overwrite;
Json::Value & config = command["config"];
if (jsonString.size() > 0)
{

View File

@ -114,7 +114,7 @@ public:
/// @param jsonString The JSON String(s) to write
/// @param create Specifies whether the nonexistent json string to be created
///
void setConfig(const std::string & jsonString, bool create);
void setConfig(const std::string & jsonString, bool create, bool overwrite);
///
/// Set the color transform of the leds

View File

@ -91,6 +91,7 @@ int main(int argc, char * argv[])
SwitchParameter<> & argSchemaGet = parameters.add<SwitchParameter<> >(0x0, "schemaGet" , "Print the json schema for Hyperion configuration");
StringParameter & argConfigSet = parameters.add<StringParameter>('W', "configSet", "Write to the actual loaded configuration file. Should be a Json object string.");
SwitchParameter<> & argCreate = parameters.add<SwitchParameter<> >(0x0, "createkeys", "Create non exist Json Entry(s) in the actual loaded configuration file. Argument to use in combination with configSet.");
SwitchParameter<> & argOverwriteConfig = parameters.add<SwitchParameter<> >(0x0, "overwrite", "Overwrite the actual loaded configuration file with the Json object string from configSet. Argument to use in combination with configSet.");
// set the default values
argAddress.setDefault(defaultServerAddress.toStdString());
@ -219,7 +220,7 @@ int main(int argc, char * argv[])
}
else if (argConfigSet.isSet())
{
connection.setConfig(argConfigSet.getValue(), argCreate.isSet());
connection.setConfig(argConfigSet.getValue(), argCreate.isSet(), argOverwriteConfig.isSet());
}
else if (colorModding)
{