diff options
author | Alex Gleason <alex@alexgleason.me> | 2021-06-14 17:27:29 -0500 |
---|---|---|
committer | Alex Gleason <alex@alexgleason.me> | 2021-06-14 17:27:29 -0500 |
commit | 9a768429a3a79faacad47aa19ff2742dacdf245d (patch) | |
tree | b41b4d53811bc510b326ac124fbc875ba42b452c /lib/mix | |
parent | a9106e4f13fa3ad6d0dbddd0f4f4e0647875b58c (diff) | |
download | pleroma-9a768429a3a79faacad47aa19ff2742dacdf245d.tar.gz |
Frontend: enable CLI task
Diffstat (limited to 'lib/mix')
-rw-r--r-- | lib/mix/tasks/pleroma/frontend.ex | 63 |
1 files changed, 59 insertions, 4 deletions
diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex index 9b151c3bd..819cd9f6a 100644 --- a/lib/mix/tasks/pleroma/frontend.ex +++ b/lib/mix/tasks/pleroma/frontend.ex @@ -32,13 +32,68 @@ defmodule Mix.Tasks.Pleroma.Frontend do ] ) - options - |> Keyword.put(:name, name) - |> opts_to_frontend() - |> Frontend.install() + shell_info("Installing frontend #{name}...") + + with %Frontend{} = fe <- + options + |> Keyword.put(:name, name) + |> opts_to_frontend() + |> Frontend.install() do + shell_info("Frontend #{fe.name} installed") + else + error -> + shell_error("Failed to install frontend") + exit(inspect(error)) + end + end + + def run(["enable", name | args]) do + start_pleroma() + + {options, [], []} = + OptionParser.parse( + args, + strict: [ + ref: :string, + build_url: :string, + build_dir: :string, + file: :string, + admin: :boolean, + primary: :boolean + ] + ) + + frontend_type = get_frontend_type(options) + + shell_info("Enabling frontend #{name}...") + + with %Frontend{} = fe <- + options + |> Keyword.put(:name, name) + |> opts_to_frontend() + |> Frontend.enable(frontend_type) do + shell_info("Frontend #{fe.name} enabled") + else + error -> + shell_error("Failed to enable frontend") + exit(inspect(error)) + end end defp opts_to_frontend(opts) do struct(Frontend, opts) end + + defp get_frontend_type(opts) do + case Enum.into(opts, %{}) do + %{admin: true, primary: true} -> + raise "Invalid command. Only one frontend type may be selected." + + %{admin: true} -> + :admin + + _ -> + :primary + end + end end |