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 @doc "Common functions to be reused in mix tasks"
8 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
10 if Pleroma.Config.get(:env) != :test do
11 Application.put_env(:logger, :console, level: :debug)
14 {:ok, _} = Application.ensure_all_started(:pleroma)
16 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
21 defp pleroma_rebooted? do
22 if Restarter.Pleroma.rebooted?() do
31 Application.load(:pleroma)
34 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
35 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
38 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
39 prompt_message = "#{prompt} [#{defname || defval}] "
43 do: Mix.shell().prompt(prompt_message),
44 else: :io.get_line(prompt_message)
50 shell_prompt(prompt, defval, defname)
61 def shell_yes?(message) do
63 do: Mix.shell().yes?("Continue?"),
64 else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
67 def shell_info(message) do
69 do: Mix.shell().info(message),
70 else: IO.puts(message)
73 def shell_error(message) do
75 do: Mix.shell().error(message),
76 else: IO.puts(:stderr, message)
79 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
80 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
82 def escape_sh_path(path) do
83 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')