MCPcopy Create free account
hub / github.com/DFHack/dfhack / enable

Method enable

library/Commands.cpp:114–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 14

has_backslashesFunction · 0.85
CallLuaModuleFunctionFunction · 0.85
GetAliasCommandMethod · 0.80
findScriptMethod · 0.80
enableLuaScriptMethod · 0.80
can_set_enabledMethod · 0.80
set_enabledMethod · 0.80
can_be_enabledMethod · 0.80
c_strMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected