comparison irccdctl/cli.cpp @ 802:f26bb089232d

irccdctl: fix alias invocations
author David Demelier <markand@malikania.fr>
date Mon, 12 Nov 2018 21:42:23 +0100
parents 3c090c1ff4f0
children d55a64c6586b
comparison
equal deleted inserted replaced
801:fe27ed0c1eae 802:f26bb089232d
185 { "onWhois", onWhois } 185 { "onWhois", onWhois }
186 }; 186 };
187 187
188 void get_event(ctl::controller& ctl, std::string fmt) 188 void get_event(ctl::controller& ctl, std::string fmt)
189 { 189 {
190 ctl.read([&ctl, fmt] (auto code, auto message) { 190 ctl.recv([&ctl, fmt] (auto code, auto message) {
191 if (code) 191 if (code)
192 throw std::system_error(code); 192 throw std::system_error(code);
193 193
194 const auto event = deserializer(message).get<std::string>("event"); 194 const auto event = deserializer(message).get<std::string>("event");
195 const auto it = events.find(event ? *event : ""); 195 const auto it = events.find(event ? *event : "");
266 bind<watch_cli>() 266 bind<watch_cli>()
267 }; 267 };
268 268
269 void cli::recv_response(ctl::controller& ctl, nlohmann::json req, handler_t handler) 269 void cli::recv_response(ctl::controller& ctl, nlohmann::json req, handler_t handler)
270 { 270 {
271 ctl.read([&ctl, req, handler, this] (auto code, auto message) { 271 ctl.recv([&ctl, req, handler, this] (auto code, auto message) {
272 if (code) 272 if (code)
273 throw std::system_error(code); 273 throw std::system_error(code);
274 274
275 const auto c = deserializer(message).get<std::string>("command"); 275 const auto c = deserializer(message).get<std::string>("command");
276 276
277 if (!c) { 277 if (!c)
278 recv_response(ctl, std::move(req), std::move(handler)); 278 recv_response(ctl, std::move(req), std::move(handler));
279 return; 279 else if (handler)
280 }
281
282 if (handler)
283 handler(std::move(message)); 280 handler(std::move(message));
284 }); 281 });
285 } 282 }
286 283
287 void cli::request(ctl::controller& ctl, nlohmann::json req, handler_t handler) 284 void cli::request(ctl::controller& ctl, nlohmann::json req, handler_t handler)
288 { 285 {
289 ctl.write(req, [&ctl, req, handler, this] (auto code) { 286 ctl.send(req, [&ctl, req, handler, this] (auto code) {
290 if (code) 287 if (code)
291 throw std::system_error(code); 288 throw std::system_error(code);
292 289
293 recv_response(ctl, std::move(req), std::move(handler)); 290 recv_response(ctl, std::move(req), std::move(handler));
294 }); 291 });