0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 16:34:13 +01:00

modules/console: Add db command with list default sub-command.

This commit is contained in:
Jason Volk 2018-02-07 20:17:26 -08:00
parent f04ba38b42
commit a517acea60

View file

@ -26,6 +26,7 @@ std::stringstream out;
static bool console_cmd__state(const string_view &line);
static bool console_cmd__event(const string_view &line);
static bool console_cmd__key(const string_view &line);
static bool console_cmd__db(const string_view &line);
static bool console_cmd__net(const string_view &line);
static bool console_cmd__mod(const string_view &line);
@ -52,6 +53,9 @@ try
case hash("net"):
return console_cmd__net(args);
case hash("db"):
return console_cmd__db(args);
case hash("key"):
return console_cmd__key(args);
@ -146,6 +150,62 @@ console_cmd__mod_syms(const string_view &line)
return true;
}
//
// db
//
static bool console_cmd__db_list(const string_view &line);
bool
console_cmd__db(const string_view &line)
{
const auto args
{
tokens_after(line, ' ', 0)
};
switch(hash(token(line, " ", 0)))
{
default:
case hash("list"):
return console_cmd__db_list(args);
}
}
bool
console_cmd__db_list(const string_view &line)
{
const auto available
{
db::available()
};
for(const auto &path : available)
{
const auto name
{
lstrip(path, db::path("/"))
};
const auto it
{
db::database::dbs.find(name)
};
const auto &light
{
it != end(db::database::dbs)? "\033[1;42m \033[0m" : " "
};
out << "[" << light << "]"
<< " " << name
<< " `" << path << "'"
<< std::endl;
}
return true;
}
//
// net
//