| 265 | } |
| 266 | |
| 267 | void ::Cli::writeConfigFile() |
| 268 | { |
| 269 | json j = json::object(); |
| 270 | |
| 271 | // Write each flag |
| 272 | for (Flag* f : Global::getFlagList()) |
| 273 | f->writeToConfig(j); |
| 274 | |
| 275 | // Dump using specified indentation. This is important for comments, since they use the same indentation! |
| 276 | std::string dumped = j.dump(JSON_DUMP_INDENTATION); |
| 277 | |
| 278 | // Another pass, to insert the comments |
| 279 | for (Flag* f : Global::getFlagList()) |
| 280 | dumped = f->documentConfigText(dumped); |
| 281 | |
| 282 | // Write that one to disk now. Ensure the userdata-folder exists first, though |
| 283 | std::string userdata = Utils::getUserDataLocation(); |
| 284 | if (!Utils::mkdir(userdata)) |
| 285 | LogError() << "Failed to create userdata-directory at: " << userdata; |
| 286 | |
| 287 | // Now create the file |
| 288 | if (!Utils::writeFile("config.json", userdata, dumped)) |
| 289 | LogError() << "Failed to write config-file to: " << userdata << "/config.json"; |
| 290 | } |
nothing calls this directly
no test coverage detected