forked from AkkomaGang/akkoma
Support listing groups, listing keys in a group, and dumping the config based on group or specific key in that group
This commit is contained in:
parent
a51da3c1d8
commit
67437feafc
1 changed files with 63 additions and 12 deletions
|
@ -47,35 +47,61 @@ def run(["dump"]) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["dump" | dbkey]) do
|
def run(["dump" | args]) when is_list(args) and length(args) < 3 do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
dbkey = dbkey |> List.first() |> String.to_atom()
|
if length(args) > 1 do
|
||||||
|
[group, key] = args
|
||||||
ConfigDB
|
dump_key(group, key)
|
||||||
|> Repo.all()
|
else
|
||||||
|> Enum.filter(fn x ->
|
[group] = args
|
||||||
if x.key == dbkey do
|
dump_group(group)
|
||||||
x |> dump
|
end
|
||||||
end
|
|
||||||
end)
|
|
||||||
else
|
else
|
||||||
_ -> configdb_not_enabled()
|
_ -> configdb_not_enabled()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["groups"]) do
|
def run(["groups"]) do
|
||||||
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
groups =
|
||||||
|
ConfigDB
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.map(fn x -> x.group end)
|
||||||
|
|> Enum.sort()
|
||||||
|
|> Enum.uniq()
|
||||||
|
|
||||||
|
if length(groups) > 0 do
|
||||||
|
shell_info("The following configuration groups are set in ConfigDB:\r\n")
|
||||||
|
groups |> Enum.each(fn x -> shell_info("- #{x}") end)
|
||||||
|
shell_info("\r\n")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
_ -> configdb_not_enabled()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(["keys" | group]) do
|
||||||
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
keys =
|
keys =
|
||||||
ConfigDB
|
ConfigDB
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|> Enum.map(fn x -> x.key end)
|
|> Enum.map(fn x ->
|
||||||
|
if x.group == group do
|
||||||
|
x.key
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|> Enum.sort()
|
||||||
|
|> Enum.uniq()
|
||||||
|
|> Enum.reject(fn x -> x == nil end)
|
||||||
|
|
||||||
if length(keys) > 0 do
|
if length(keys) > 0 do
|
||||||
shell_info("The following configuration keys are set in ConfigDB:\r\n")
|
shell_info("The following configuration keys under :#{group} are set in ConfigDB:\r\n")
|
||||||
keys |> Enum.each(fn x -> shell_info("- #{x}") end)
|
keys |> Enum.each(fn x -> shell_info("- #{x}") end)
|
||||||
shell_info("\r\n")
|
shell_info("\r\n")
|
||||||
end
|
end
|
||||||
|
@ -257,4 +283,29 @@ defp configdb_not_enabled do
|
||||||
"ConfigDB not enabled. Please check the value of :configurable_from_database in your configuration."
|
"ConfigDB not enabled. Please check the value of :configurable_from_database in your configuration."
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp dump_key(group, key) do
|
||||||
|
group = group |> String.to_atom()
|
||||||
|
key = key |> String.to_atom()
|
||||||
|
|
||||||
|
ConfigDB
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.filter(fn x ->
|
||||||
|
if x.group == group && x.key == key do
|
||||||
|
x |> dump
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp dump_group(group) do
|
||||||
|
group = group |> String.to_atom()
|
||||||
|
|
||||||
|
ConfigDB
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.filter(fn x ->
|
||||||
|
if x.group == group do
|
||||||
|
x |> dump
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue