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 Mix.Task.run("app.start")
9 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
11 if Pleroma.Config.get(:env) != :test do
12 Application.put_env(:logger, :console, level: :debug)
15 {:ok, _} = Application.ensure_all_started(:pleroma)
17 if Pleroma.Config.get(:env) not in [:test, :benchmark] do
22 defp pleroma_rebooted? do
23 if Restarter.Pleroma.rebooted?() do
32 Application.load(:pleroma)
35 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
36 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
39 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
40 prompt_message = "#{prompt} [#{defname || defval}] "
44 do: Mix.shell().prompt(prompt_message),
45 else: :io.get_line(prompt_message)
51 shell_prompt(prompt, defval, defname)
62 def shell_yes?(message) do
64 do: Mix.shell().yes?("Continue?"),
65 else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
68 def shell_info(message) do
70 do: Mix.shell().info(message),
71 else: IO.puts(message)
74 def shell_error(message) do
76 do: Mix.shell().error(message),
77 else: IO.puts(:stderr, message)
80 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
81 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
83 def escape_sh_path(path) do
84 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')