From 47bda85f3f19a8d2ccfeabf2e9c1f97204756185 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 11 Jan 2019 17:40:14 -0800 Subject: [PATCH] modules/console: Add event cached cmd. --- modules/console.cc | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index a7252b0a9..2f6c50a91 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -5591,6 +5591,70 @@ console_cmd__event__bad(opt &out, const string_view &line) return true; } +bool +console_cmd__event__cached(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "event_id|event_idx", + }}; + + const string_view id + { + param.at(0) + }; + + static const m::event::fetch::opts opts + { + m::event::keys::exclude {} + }; + + if(valid(m::id::EVENT, id)) + { + const m::event::id event_id + { + id + }; + + const bool cached + { + m::cached(event_id, opts) + }; + + out << event_id << " is" + << (cached? " " : " not ") + << "cached" + << std::endl; + + return true; + } + else if(try_lex_cast(id)) + { + const m::event::idx event_idx + { + lex_cast(id) + }; + + const bool cached + { + m::cached(event_idx, opts) + }; + + out << "idx[" << event_idx << "] is" + << (cached? " " : " not ") + << "cached" + << std::endl; + + return true; + } + else throw m::BAD_REQUEST + { + "Not a valid event_id or `event_idx" + }; + + return true; +} + bool console_cmd__event__erase(opt &out, const string_view &line) {