0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 15:00:51 +01:00

modules/console: Allow lists of module names to mod cmds.

This commit is contained in:
Jason Volk 2018-04-24 17:13:44 -07:00
parent 6b4e188682
commit 2b6fd1c985

View file

@ -627,55 +627,66 @@ console_cmd__mod__syms(opt &out, const string_view &line)
bool
console_cmd__mod__reload(opt &out, const string_view &line)
{
const std::string name
const auto names
{
token(line, ' ', 0)
tokens<std::vector>(line, ' ')
};
if(!m::modules.erase(name))
for(auto it(names.begin()); it != names.end(); ++it)
{
const auto &name{*it};
if(m::modules.erase(std::string{name}))
out << name << " unloaded." << std::endl;
else
out << name << " is not loaded." << std::endl;
return true;
}
m::modules.emplace(name, name);
out << "reload " << name << std::endl;
for(auto it(names.rbegin()); it != names.rend(); ++it)
{
const auto &name{*it};
if(m::modules.emplace(std::string{name}, name).second)
out << name << " loaded." << std::endl;
else
out << name << " is already loaded." << std::endl;
}
return true;
}
bool
console_cmd__mod__load(opt &out, const string_view &line)
{
const std::string name
tokens(line, ' ', [&out]
(const string_view &name)
{
token(line, ' ', 0)
};
if(m::modules.find(name) != end(m::modules))
{
out << name << " is already loaded." << std::endl;
return true;
return;
}
m::modules.emplace(name, name);
m::modules.emplace(std::string{name}, name);
out << name << " loaded." << std::endl;
});
return true;
}
bool
console_cmd__mod__unload(opt &out, const string_view &line)
{
const std::string name
tokens(line, ' ', [&out]
(const string_view &name)
{
token(line, ' ', 0)
};
if(!m::modules.erase(name))
if(!m::modules.erase(std::string{name}))
{
out << name << " is not loaded." << std::endl;
return true;
return;
}
out << "unloaded " << name << std::endl;
});
return true;
}