aboutsummaryrefslogtreecommitdiff
path: root/shard/lib/cli
diff options
context:
space:
mode:
Diffstat (limited to 'shard/lib/cli')
-rw-r--r--shard/lib/cli/cli.ex36
1 files changed, 34 insertions, 2 deletions
diff --git a/shard/lib/cli/cli.ex b/shard/lib/cli/cli.ex
index 8495b93..a9eaa95 100644
--- a/shard/lib/cli/cli.ex
+++ b/shard/lib/cli/cli.ex
@@ -105,7 +105,7 @@ defmodule SCLI do
end
defp handle_command(state, ["list"]) do
- IO.puts "Private conversations:"
+ IO.puts "\nPrivate conversations:\n----"
for {_chid, %SApp.Chat.PrivChat.Manifest{pk_list: pk_list}, _} <- Shard.Manager.list_shards do
pk_list
|> Enum.filter(&(&1 != state.pk))
@@ -114,10 +114,11 @@ defmodule SCLI do
|> IO.puts
end
- IO.puts "Public channels we are connected to:"
+ IO.puts "\nPublic channels we are connected to:\n----"
for {_chid, %SApp.Chat.Manifest{channel: chan}, _} <- Shard.Manager.list_shards do
IO.puts "##{chan}"
end
+ IO.puts ""
state
end
@@ -209,10 +210,41 @@ defmodule SCLI do
end
defp handle_command(state, ["shards"]) do
+ IO.puts("\nList of shards:\n----")
Shard.Manager.list_shards
|> Enum.map(&(ShardURI.from_manifest(elem(&1, 1))))
|> Enum.sort()
|> Enum.map(&IO.puts/1)
+ IO.puts("")
+ state
+ end
+
+ defp handle_command(state, ["delete", uri]) do
+ manifest = ShardURI.to_manifest uri
+ id = SData.term_hash manifest
+ case Shard.Manager.delete(id) do
+ :ok -> IO.puts "OK"
+ {:error, :not_found} -> IO.puts "Shard not found"
+ {:error, :pinned} -> IO.puts "Shard is pinned, could not be deleted"
+ end
+ state
+ end
+
+ defp handle_command(state, ["info", uri]) do
+ manifest = ShardURI.to_manifest uri
+ case manifest do
+ %SApp.File.Manifest{} ->
+ pid = Shard.Manager.find_or_start manifest
+ info = GenServer.call(pid, :get_info)
+ IO.puts(inspect(info, pretty: true, width: 40))
+ _ ->
+ IO.puts("Info not supported for this shard")
+ end
+ state
+ end
+
+ defp handle_command(state, ["help"]) do
+ IO.puts("See README.md for help")
state
end