| 20 | namespace cli { |
| 21 | |
| 22 | bool runModelUpdateCommand(const openstudio::path& p, bool keep) { |
| 23 | std::vector<openstudio::path> osmPaths; |
| 24 | |
| 25 | openstudio::osversion::VersionTranslator vt; |
| 26 | |
| 27 | if (openstudio::filesystem::is_directory(p)) { |
| 28 | for (auto const& dir_entry : boost::filesystem::directory_iterator{p}) { |
| 29 | const auto& thePath = dir_entry.path(); |
| 30 | if (openstudio::filesystem::is_regular_file(thePath) && thePath.extension() == ".osm") { |
| 31 | osmPaths.emplace_back(thePath); |
| 32 | } |
| 33 | } |
| 34 | } else { |
| 35 | osmPaths.push_back(p); |
| 36 | } |
| 37 | |
| 38 | bool result = true; |
| 39 | for (const auto& relPath : osmPaths) { |
| 40 | fmt::print("'{}'\n", relPath.string()); |
| 41 | auto osmPath = openstudio::filesystem::system_complete(relPath); |
| 42 | if (keep) { |
| 43 | openstudio::path backupPath = osmPath; |
| 44 | backupPath.replace_extension(openstudio::toPath(".osm.orig")); |
| 45 | openstudio::filesystem::copy_file(osmPath, backupPath, openstudio::filesystem::copy_options::overwrite_existing); |
| 46 | } |
| 47 | if (auto model_ = vt.loadModel(osmPath)) { |
| 48 | fmt::print("Updated '{}'\n", osmPath.string()); |
| 49 | model_->save(osmPath, true); |
| 50 | } else { |
| 51 | fmt::print("Could not read model at '{}'\n", osmPath.string()); |
| 52 | result = false; |
| 53 | } |
| 54 | } |
| 55 | return result; |
| 56 | } |
| 57 | |
| 58 | void executeRubyScriptCommand(openstudio::path rubyScriptPath, ScriptEngineInstance& rubyEngine, const std::vector<std::string>& arguments) { |
| 59 | rubyScriptPath = openstudio::filesystem::system_complete(rubyScriptPath); |