diff options
author | Alex Auvolat <alex@adnab.me> | 2018-07-03 15:42:17 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-07-03 15:42:17 +0200 |
commit | 8f3009715ee9ccdd7ecb54fea1244a32a29b62c0 (patch) | |
tree | 416fb96c39effa4217864bb6a93243803ba8edba /lib/cli/cli.ex | |
download | shard-8f3009715ee9ccdd7ecb54fea1244a32a29b62c0.tar.gz shard-8f3009715ee9ccdd7ecb54fea1244a32a29b62c0.zip |
Initialize shard repo with code from somewhere
Diffstat (limited to 'lib/cli/cli.ex')
-rw-r--r-- | lib/cli/cli.ex | 30 |
1 files changed, 30 insertions, 0 deletions
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 |