| 112 | } |
| 113 | |
| 114 | command_result Commands::enable(color_ostream& con, Core& core, const std::string& first, const std::vector<std::string>& parts) |
| 115 | { |
| 116 | CoreSuspender suspend; |
| 117 | bool enable = (first == "enable"); |
| 118 | auto plug_mgr = core.getPluginManager(); |
| 119 | |
| 120 | if (parts.size()) |
| 121 | { |
| 122 | command_result res{CR_FAILURE}; |
| 123 | |
| 124 | for (auto& part_ : parts) |
| 125 | { |
| 126 | // have to copy to modify as passed argument is const |
| 127 | std::string part(part_); |
| 128 | |
| 129 | if (has_backslashes(part)) |
| 130 | { |
| 131 | con.printerr("Replacing backslashes with forward slashes in \"{}\"\n", part); |
| 132 | replace_backslashes_with_forwardslashes(part); |
| 133 | } |
| 134 | |
| 135 | auto alias = core.GetAliasCommand(part, true); |
| 136 | |
| 137 | Plugin* plug = (*plug_mgr)[alias]; |
| 138 | |
| 139 | if (!plug) |
| 140 | { |
| 141 | std::filesystem::path lua = core.findScript(part + ".lua"); |
| 142 | if (!lua.empty()) |
| 143 | { |
| 144 | res = core.enableLuaScript(con, part, enable); |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | res = CR_NOT_FOUND; |
| 149 | con.printerr("No such plugin or Lua script: {}\n", part); |
| 150 | } |
| 151 | } |
| 152 | else if (!plug->can_set_enabled()) |
| 153 | { |
| 154 | res = CR_NOT_IMPLEMENTED; |
| 155 | con.printerr("Cannot {} plugin: {}\n", first, part); |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | res = plug->set_enabled(con, enable); |
| 160 | |
| 161 | if (res != CR_OK || plug->is_enabled() != enable) |
| 162 | con.printerr("Could not {} plugin: {}\n", first, part); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return res; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | for (auto& [key, plug] : *plug_mgr) |
| 171 | { |
nothing calls this directly
no test coverage detected