Print out settings that will be removed when specifying the group and key for consistency

Fix error message when specified key doesn't exist
This commit is contained in:
Mark Felder 2020-12-07 11:45:56 -06:00
parent 61494b5245
commit 93428d7c11

View File

@ -134,7 +134,18 @@ defmodule Mix.Tasks.Pleroma.Config do
group = maybe_atomize(group) group = maybe_atomize(group)
key = maybe_atomize(key) 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 end
def run(["delete", "--force", group]) do def run(["delete", "--force", group]) do
@ -157,10 +168,21 @@ defmodule Mix.Tasks.Pleroma.Config do
group = maybe_atomize(group) group = maybe_atomize(group)
key = maybe_atomize(key) key = maybe_atomize(key)
if shell_prompt("Are you sure you want to continue?", "n") in ~w(Yn Y y) do with true <- key_exists?(group, key) do
delete_key(group, key) 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 else
shell_error("No changes made.") _ ->
shell_error("No settings in ConfigDB for #{inspect(group)}, #{inspect(key)}. Aborting.")
end end
end end
@ -315,6 +337,13 @@ defmodule Mix.Tasks.Pleroma.Config do
|> Enum.any?() |> Enum.any?()
end 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) when is_atom(arg), do: arg
defp maybe_atomize(":" <> arg), do: maybe_atomize(arg) defp maybe_atomize(":" <> arg), do: maybe_atomize(arg)