changeset 329:bc7f65897762

Irccdctl: bring back server-join
author David Demelier <markand@malikania.fr>
date Tue, 08 Nov 2016 13:10:46 +0100
parents b9cb459bf93a
children a167353ab89e
files irccdctl/cli-server-join.cpp irccdctl/cli-server-join.hpp
diffstat 2 files changed, 107 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/irccdctl/cli-server-join.cpp	Tue Nov 08 13:10:46 2016 +0100
@@ -0,0 +1,54 @@
+/*
+ * cli-server-join.cpp -- implementation of irccdctl server-join
+ *
+ * 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 "cli-server-join.hpp"
+
+namespace irccd {
+
+namespace cli {
+
+ServerJoinCli::ServerJoinCli()
+    : Cli("server-join",
+          "join a channel",
+          "server-join server channel [password]",
+          "Join the specified channel, the password is optional.\n\n"
+          "Example:\n"
+          "\tirccdctl server-join freenode #test\n"
+          "\tirccdctl server-join freenode #private-club secret")
+{
+}
+
+void ServerJoinCli::exec(Irccdctl &irccdctl, const std::vector<std::string> &args)
+{
+    if (args.size() < 2)
+        throw std::invalid_argument("server-join requires at least 2 arguments");
+
+    auto object = nlohmann::json::object({
+        { "server",     args[0]         },
+        { "channel",    args[1]         }
+    });
+
+    if (args.size() == 3)
+        object["password"] = args[2];
+
+    check(request(irccdctl, object));
+}
+
+} // !cli
+
+} // !irccd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/irccdctl/cli-server-join.hpp	Tue Nov 08 13:10:46 2016 +0100
@@ -0,0 +1,53 @@
+/*
+ * cli-server-join.hpp -- implementation of irccdctl server-join
+ *
+ * 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.
+ */
+
+#ifndef IRCCDCTL_CLI_SERVER_JOIN_HPP
+#define IRCCDCTL_CLI_SERVER_JOIN_HPP
+
+/**
+ * \file cli-server-join.hpp
+ * \brief Implementation of irccdctl server-join.
+ */
+
+#include "cli.hpp"
+
+namespace irccd {
+
+namespace cli {
+
+/**
+ * \brief Implementation of irccdctl server-join.
+ */
+class ServerJoinCli : public Cli {
+public:
+    /**
+     * Default constructor.
+     */
+    ServerJoinCli();
+
+    /**
+     * \copydoc Cli::exec
+     */
+    void exec(Irccdctl &irccdctl, const std::vector<std::string> &args) override;
+};
+
+} // !command
+
+} // !irccd
+
+#endif // !IRCCDCTL_CLI_SERVER_JOIN_HPP