From f25929e45cfbe25bb7401c9af126d353e1eaef86 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 6 Nov 2018 15:22:30 +0100 Subject: Cleanup ; make file download from CLI doable --- shard/lib/cli/cli.ex | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'shard/lib/cli/cli.ex') 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 -- cgit v1.2.3