From 93428d7c11ce30d38fa23192c9a15e2e713a50be Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 7 Dec 2020 11:45:56 -0600 Subject: [PATCH] Print out settings that will be removed when specifying the group and key for consistency Fix error message when specified key doesn't exist --- lib/mix/tasks/pleroma/config.ex | 37 +++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index d1af0a60c..d7e2e97e7 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -134,7 +134,18 @@ defmodule Mix.Tasks.Pleroma.Config do group = maybe_atomize(group) key = maybe_atomize(key) - delete_key(group, key) + with true <- key_exists?(group, key) do + shell_info("The following settings will be removed from ConfigDB:\n") + + group + |> ConfigDB.get_by_group_and_key(key) + |> dump() + + delete_key(group, key) + else + _ -> + shell_error("No settings in ConfigDB for #{inspect(group)}, #{inspect(key)}. Aborting.") + end end def run(["delete", "--force", group]) do @@ -157,10 +168,21 @@ defmodule Mix.Tasks.Pleroma.Config do group = maybe_atomize(group) key = maybe_atomize(key) - if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do - delete_key(group, key) + with true <- key_exists?(group, key) do + shell_info("The following settings will be removed from ConfigDB:\n") + + group + |> ConfigDB.get_by_group_and_key(key) + |> dump() + + if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do + delete_key(group, key) + else + shell_error("No changes made.") + end else - shell_error("No changes made.") + _ -> + shell_error("No settings in ConfigDB for #{inspect(group)}, #{inspect(key)}. Aborting.") end end @@ -315,6 +337,13 @@ defmodule Mix.Tasks.Pleroma.Config do |> Enum.any?() end + defp key_exists?(group, key) do + group + |> ConfigDB.get_by_group_and_key(key) + |> is_nil + |> Kernel.!() + end + defp maybe_atomize(arg) when is_atom(arg), do: arg defp maybe_atomize(":" <> arg), do: maybe_atomize(arg) -- 2.45.2