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

modules/s_conf: Add default_conf w/ console cmd to set item to default value.

This commit is contained in:
Jason Volk 2018-11-02 04:49:56 -07:00
parent cf46ad916c
commit b8b6fbea37
2 changed files with 56 additions and 0 deletions

View file

@ -832,6 +832,42 @@ console_cmd__conf__rehash(opt &out, const string_view &line)
return true; return true;
} }
bool
console_cmd__conf__default(opt &out, const string_view &line)
{
const params param{line, " ",
{
"prefix"
}};
using prototype = void (const string_view &);
static mods::import<prototype> default_conf
{
"s_conf", "default_conf"
};
string_view prefix
{
param.at("prefix", "*"_sv)
};
if(prefix == "*")
prefix = string_view{};
default_conf(prefix);
out << "Set runtime conf items"
<< (prefix? " with the prefix "_sv : string_view{})
<< (prefix? prefix : string_view{})
<< " to their default value."
<< std::endl
<< "Note: These values must be saved with the rehash command"
<< " to survive a restart/reload."
<< std::endl;
return true;
}
bool bool
console_cmd__conf__reload(opt &out, const string_view &line) console_cmd__conf__reload(opt &out, const string_view &line)
{ {

View file

@ -10,6 +10,7 @@
using namespace ircd; using namespace ircd;
extern "C" void default_conf(const string_view &prefix);
extern "C" void rehash_conf(const string_view &prefix, const bool &existing); extern "C" void rehash_conf(const string_view &prefix, const bool &existing);
extern "C" void reload_conf(); extern "C" void reload_conf();
extern "C" void refresh_conf(); extern "C" void refresh_conf();
@ -290,6 +291,25 @@ rehash_conf(const string_view &prefix,
} }
} }
void
default_conf(const string_view &prefix)
{
for(const auto &p : conf::items)
{
const auto &key{p.first};
if(prefix && !startswith(key, prefix))
continue;
const auto &item{p.second}; assert(item);
const auto value
{
unquote(item->feature["default"])
};
conf::set(key, value);
}
}
void void
reload_conf() reload_conf()
{ {