aboutsummaryrefslogtreecommitdiff
path: root/lib/cli
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-07-03 15:42:17 +0200
committerAlex Auvolat <alex@adnab.me>2018-07-03 15:42:17 +0200
commit8f3009715ee9ccdd7ecb54fea1244a32a29b62c0 (patch)
tree416fb96c39effa4217864bb6a93243803ba8edba /lib/cli
downloadshard-8f3009715ee9ccdd7ecb54fea1244a32a29b62c0.tar.gz
shard-8f3009715ee9ccdd7ecb54fea1244a32a29b62c0.zip
Initialize shard repo with code from somewhere
Diffstat (limited to 'lib/cli')
-rw-r--r--lib/cli/cli.ex30
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