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
17 @cachex_children ["object", "user"]
18 @doc "Common functions to be reused in mix tasks"
20 Pleroma.Config.Holder.save_default()
21 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
23 if Pleroma.Config.get(:env) != :test do
24 Application.put_env(:logger, :console, level: :debug)
28 if Application.get_env(:tesla, :adapter) == Tesla.Adapter.Gun do
34 Enum.each(apps, &Application.ensure_all_started/1)
38 {Pleroma.Config.TransferTask, false},
42 cachex_children = Enum.map(@cachex_children, &Pleroma.Application.build_cachex(&1, []))
44 Supervisor.start_link(children ++ cachex_children,
45 strategy: :one_for_one,
46 name: Pleroma.Supervisor
49 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
54 defp pleroma_rebooted? do
55 if Restarter.Pleroma.rebooted?() do
64 Application.load(:pleroma)
67 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
68 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
71 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
72 prompt_message = "#{prompt} [#{defname || defval}] "
76 do: Mix.shell().prompt(prompt_message),
77 else: :io.get_line(prompt_message)
83 shell_prompt(prompt, defval, defname)
94 def shell_yes?(message) do
96 do: Mix.shell().yes?("Continue?"),
97 else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
100 def shell_info(message) do
102 do: Mix.shell().info(message),
103 else: IO.puts(message)
106 def shell_error(message) do
108 do: Mix.shell().error(message),
109 else: IO.puts(:stderr, message)
112 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
113 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
115 def escape_sh_path(path) do
116 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')