From 8f3009715ee9ccdd7ecb54fea1244a32a29b62c0 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 3 Jul 2018 15:42:17 +0200 Subject: Initialize shard repo with code from somewhere --- lib/cli/cli.ex | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/cli/cli.ex (limited to 'lib/cli/cli.ex') diff --git a/lib/cli/cli.ex b/lib/cli/cli.ex new file mode 100644 index 0000000..4643351 --- /dev/null +++ b/lib/cli/cli.ex @@ -0,0 +1,30 @@ +defmodule SCLI do + def run() do + str = "say: " |> IO.gets |> String.trim + cond do + str == "/quit" -> + nil + String.slice(str, 0..0) == "/" -> + command = str |> String.slice(1..-1) |> String.split(" ") + handle_command(command) + run() + true -> + SApp.Chat.send(str) + run() + end + end + + def handle_command(["connect", ipstr, portstr]) do + {:ok, ip} = :inet.parse_address (to_charlist ipstr) + {port, _} = Integer.parse portstr + SNet.TCPServer.add_peer(ip, port) + end + + def handle_command(["nick", nick]) do + Shard.Identity.set_nickname nick + end + + def handle_command(_cmd) do + IO.puts "Invalid command" + end +end -- cgit v1.2.3