0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

modules/console: Adjust the state commands to use a root node ID arg for now.

This commit is contained in:
Jason Volk 2018-02-08 13:25:59 -08:00
parent 7346d9dcdb
commit 7bff223748

View file

@ -520,7 +520,7 @@ console_cmd__event__default(const string_view &line)
// state // state
// //
static bool console_cmd__state_head(const string_view &line); static bool console_cmd__state_root(const string_view &line);
static bool console_cmd__state_count(const string_view &line); static bool console_cmd__state_count(const string_view &line);
static bool console_cmd__state_get(const string_view &line); static bool console_cmd__state_get(const string_view &line);
static bool console_cmd__state_each(const string_view &line); static bool console_cmd__state_each(const string_view &line);
@ -536,8 +536,8 @@ console_cmd__state(const string_view &line)
switch(hash(token(line, " ", 0))) switch(hash(token(line, " ", 0)))
{ {
case hash("head"): case hash("root"):
return console_cmd__state_head(args); return console_cmd__state_root(args);
case hash("get"): case hash("get"):
return console_cmd__state_get(args); return console_cmd__state_get(args);
@ -556,19 +556,6 @@ console_cmd__state(const string_view &line)
} }
} }
bool
console_cmd__state_head(const string_view &line)
{
const m::room::id room_id
{
token(line, ' ', 0)
};
char buf[m::state::ID_MAX_SZ];
out << m::state::get_head(buf, room_id) << std::endl;
return true;
}
bool bool
console_cmd__state_count(const string_view &line) console_cmd__state_count(const string_view &line)
{ {
@ -577,13 +564,12 @@ console_cmd__state_count(const string_view &line)
token(line, ' ', 0) token(line, ' ', 0)
}; };
char buf[m::state::ID_MAX_SZ]; const string_view root
const string_view head
{ {
startswith(arg, '!')? m::state::get_head(buf, arg) : arg arg
}; };
out << m::state::count(head) << std::endl; out << m::state::count(root) << std::endl;
return true; return true;
} }
@ -600,13 +586,12 @@ console_cmd__state_each(const string_view &line)
token(line, ' ', 1) token(line, ' ', 1)
}; };
char buf[m::state::ID_MAX_SZ]; const string_view root
const string_view head
{ {
startswith(arg, '!')? m::state::get_head(buf, arg) : arg arg
}; };
m::state::each(head, type, [] m::state::each(root, type, []
(const string_view &key, const string_view &val) (const string_view &key, const string_view &val)
{ {
out << key << " => " << val << std::endl; out << key << " => " << val << std::endl;
@ -619,7 +604,7 @@ console_cmd__state_each(const string_view &line)
bool bool
console_cmd__state_get(const string_view &line) console_cmd__state_get(const string_view &line)
{ {
const m::room::id room_id const string_view root
{ {
token(line, ' ', 0) token(line, ' ', 0)
}; };
@ -634,7 +619,7 @@ console_cmd__state_get(const string_view &line)
token(line, ' ', 2) token(line, ' ', 2)
}; };
m::state::get__room(room_id, type, state_key, [] m::state::get(root, type, state_key, []
(const auto &value) (const auto &value)
{ {
out << "got: " << value << std::endl; out << "got: " << value << std::endl;
@ -651,13 +636,12 @@ console_cmd__state_dfs(const string_view &line)
token(line, ' ', 0) token(line, ' ', 0)
}; };
char buf[m::state::ID_MAX_SZ]; const string_view root
const string_view head
{ {
startswith(arg, '!')? m::state::get_head(buf, arg) : arg arg
}; };
m::state::dfs(head, [] m::state::dfs(root, []
(const auto &key, const string_view &val, const uint &depth, const uint &pos) (const auto &key, const string_view &val, const uint &depth, const uint &pos)
{ {
out << std::setw(2) << depth << " + " << pos out << std::setw(2) << depth << " + " << pos
@ -670,6 +654,19 @@ console_cmd__state_dfs(const string_view &line)
return true; return true;
} }
bool
console_cmd__state_root(const string_view &line)
{
const m::event::id event_id
{
token(line, ' ', 0)
};
char buf[m::state::ID_MAX_SZ];
out << m::dbs::state_root(buf, event_id) << std::endl;
return true;
}
// //
// exec // exec
// //