Mercurial > irccd
changeset 343:3d927ba4af75
Irccdctl: bring back plugin-config
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 12 Nov 2016 22:57:47 +0100 |
parents | 40abc6522cd7 |
children | 4665fffff6f2 |
files | irccdctl/cli-plugin-config.cpp irccdctl/cli-plugin-config.hpp |
diffstat | 2 files changed, 95 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/irccdctl/cli-plugin-config.cpp Sat Nov 12 22:57:47 2016 +0100 @@ -0,0 +1,90 @@ +/* + * cli-plugin-config.cpp -- implementation of irccdctl plugin-info + * + * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <util.hpp> + +#include "cli-plugin-config.hpp" + +namespace irccd { + +namespace cli { + +void PluginConfigCli::set(Irccdctl &irccdctl, const std::vector<std::string> &args) +{ + check(request(irccdctl, nlohmann::json::object({ + { "plugin", args[0] }, + { "variable", args[1] }, + { "value", args[2] } + }))); +} + +void PluginConfigCli::get(Irccdctl &irccdctl, const std::vector<std::string> &args) +{ + auto result = request(irccdctl, nlohmann::json::object({ + { "plugin", args[0] }, + { "variable", args[1] } + })); + + check(result); + + if (result["variables"].is_object()) + std::cout << util::json::pretty(result["variables"][args[1]]) << std::endl; +} + +void PluginConfigCli::getall(Irccdctl &irccdctl, const std::vector<std::string> &args) +{ + auto result = request(irccdctl, nlohmann::json::object({{ "plugin", args[0] }})); + + check(result); + + auto variables = result["variables"]; + + for (auto v = variables.begin(); v != variables.end(); ++v) + std::cout << std::setw(16) << std::left << v.key() << " : " << util::json::pretty(v.value()) << std::endl; +} + +PluginConfigCli::PluginConfigCli() + : Cli("plugin-config", + "configure a plugin", + "plugin-config plugin [variable] [value]", + "Get or set plugin configuration.\n\n" + "Examples:\n" + "\tirccdctl plugin-config ask") +{ +} + +void PluginConfigCli::exec(Irccdctl &irccdctl, const std::vector<std::string> &args) +{ + switch (args.size()) { + case 3: + set(irccdctl, args); + break; + case 2: + get(irccdctl, args); + break; + case 1: + getall(irccdctl, args); + break; + default: + throw std::invalid_argument("plugin-config requires at least 1 argument"); + } +} + +} // !cli + +} // !irccd
--- a/irccdctl/cli-plugin-config.hpp Mon Nov 07 13:14:57 2016 +0100 +++ b/irccdctl/cli-plugin-config.hpp Sat Nov 12 22:57:47 2016 +0100 @@ -31,6 +31,11 @@ namespace cli { class PluginConfigCli : public Cli { +private: + void set(Irccdctl &, const std::vector<std::string> &); + void get(Irccdctl &, const std::vector<std::string> &); + void getall(Irccdctl &, const std::vector<std::string> &); + public: /** * Default constructor.