diff options
Diffstat (limited to 'lib/mix/tasks')
-rw-r--r-- | lib/mix/tasks/pleroma/frontend.ex | 80 |
1 files changed, 76 insertions, 4 deletions
diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex index 8334e0049..229ef10bd 100644 --- a/lib/mix/tasks/pleroma/frontend.ex +++ b/lib/mix/tasks/pleroma/frontend.ex @@ -7,6 +7,8 @@ defmodule Mix.Tasks.Pleroma.Frontend do import Mix.Pleroma + alias Pleroma.Frontend + @shortdoc "Manages bundled Pleroma frontends" @moduledoc File.read!("docs/administration/CLI_tasks/frontend.md") @@ -16,7 +18,42 @@ defmodule Mix.Tasks.Pleroma.Frontend do "none" end - def run(["install", frontend | args]) do + def run(["install", name | args]) do + start_pleroma() + + {options, [], []} = + OptionParser.parse( + args, + strict: [ + ref: :string, + build_url: :string, + build_dir: :string, + file: :string, + admin: :boolean, + primary: :boolean + ] + ) + + 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") + + if get_frontend_type(options) do + run(["enable", name] ++ args) + end + else + error -> + shell_error("Failed to install frontend") + exit(inspect(error)) + end + end + + def run(["enable", name | args]) do start_pleroma() {options, [], []} = @@ -24,13 +61,48 @@ defmodule Mix.Tasks.Pleroma.Frontend do args, strict: [ ref: :string, - static_dir: :string, build_url: :string, build_dir: :string, - file: :string + file: :string, + admin: :boolean, + primary: :boolean ] ) - Pleroma.Frontend.install(frontend, options) + frontend_type = get_frontend_type(options) || :primary + + 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: true} -> + :primary + + _ -> + nil + end end end |