| 59 | } |
| 60 | |
| 61 | command_result Commands::load(color_ostream& con, Core& core, const std::string& first, const std::vector<std::string>& parts) |
| 62 | { |
| 63 | bool all = false; |
| 64 | bool load = (first == "load"); |
| 65 | bool unload = (first == "unload"); |
| 66 | bool reload = (first == "reload"); |
| 67 | auto plug_mgr = core.getPluginManager(); |
| 68 | if (parts.size()) |
| 69 | { |
| 70 | for (const auto& p : parts) |
| 71 | { |
| 72 | if (p.size() && p[0] == '-') |
| 73 | { |
| 74 | if (p.find('a') != std::string::npos) |
| 75 | all = true; |
| 76 | } |
| 77 | } |
| 78 | auto ret = CR_OK; |
| 79 | if (all) |
| 80 | { |
| 81 | if (load && !plug_mgr->loadAll()) |
| 82 | ret = CR_FAILURE; |
| 83 | else if (unload && !plug_mgr->unloadAll()) |
| 84 | ret = CR_FAILURE; |
| 85 | else if (reload && !plug_mgr->reloadAll()) |
| 86 | ret = CR_FAILURE; |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | for (auto& p : parts) |
| 91 | { |
| 92 | if (p.empty() || p[0] == '-') |
| 93 | continue; |
| 94 | if (load && !plug_mgr->load(p)) |
| 95 | ret = CR_FAILURE; |
| 96 | else if (unload && !plug_mgr->unload(p)) |
| 97 | ret = CR_FAILURE; |
| 98 | else if (reload && !plug_mgr->reload(p)) |
| 99 | ret = CR_FAILURE; |
| 100 | } |
| 101 | } |
| 102 | if (ret != CR_OK) |
| 103 | con.printerr("{} failed\n", first.c_str()); |
| 104 | return ret; |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | con.printerr("{}: no arguments\n", first.c_str()); |
| 109 | return CR_FAILURE; |
| 110 | } |
| 111 | |
| 112 | } |
| 113 | |
| 114 | command_result Commands::enable(color_ostream& con, Core& core, const std::string& first, const std::vector<std::string>& parts) |
| 115 | { |