1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Mix.Pleroma do
6 @apps [:restarter, :ecto, :ecto_sql, :postgrex, :db_connection, :cachex]
7 @cachex_childs ["object", "user"]
8 @doc "Common functions to be reused in mix tasks"
10 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
12 if Pleroma.Config.get(:env) != :test do
13 Application.put_env(:logger, :console, level: :debug)
17 if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do
23 Enum.each(apps, &Application.ensure_all_started/1)
27 {Pleroma.Config.TransferTask, false},
31 cachex_childs = Enum.map(@cachex_childs, &Pleroma.Application.build_cachex(&1, []))
33 Supervisor.start_link(childs ++ cachex_childs,
34 strategy: :one_for_one,
35 name: Pleroma.Supervisor
38 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
43 defp pleroma_rebooted? do
44 if Restarter.Pleroma.rebooted?() do
53 Application.load(:pleroma)
56 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
57 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
60 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
61 prompt_message = "#{prompt} [#{defname || defval}] "
65 do: Mix.shell().prompt(prompt_message),
66 else: :io.get_line(prompt_message)
72 shell_prompt(prompt, defval, defname)
83 def shell_yes?(message) do
85 do: Mix.shell().yes?("Continue?"),
86 else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
89 def shell_info(message) do
91 do: Mix.shell().info(message),
92 else: IO.puts(message)
95 def shell_error(message) do
97 do: Mix.shell().error(message),
98 else: IO.puts(:stderr, message)
101 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
102 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
104 def escape_sh_path(path) do
105 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')