1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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"
7 def start_pleroma(change_logger_level \\ true) do
8 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
10 if Pleroma.Config.get(:env) != :test and change_logger_level do
12 Logger.configure(level: :debug)
15 {:ok, _} = Application.ensure_all_started(:pleroma)
19 Application.load(:pleroma)
22 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
23 Keyword.get(options, opt) || shell_prompt(prompt, defval, defname)
26 def shell_prompt(prompt, defval \\ nil, defname \\ nil) do
27 prompt_message = "#{prompt} [#{defname || defval}] "
31 do: Mix.shell().prompt(prompt_message),
32 else: :io.get_line(prompt_message)
38 shell_prompt(prompt, defval, defname)
49 def shell_yes?(message) do
51 do: Mix.shell().yes?("Continue?"),
52 else: shell_prompt(message, "Continue?") in ~w(Yn Y y)
55 def shell_info(message) do
57 do: Mix.shell().info(message),
58 else: IO.puts(message)
61 def shell_error(message) do
63 do: Mix.shell().error(message),
64 else: IO.puts(:stderr, message)
67 @doc "Performs a safe check whether `Mix.shell/0` is available (does not raise if Mix is not loaded)"
68 def mix_shell?, do: :erlang.function_exported(Mix, :shell, 0)
70 def escape_sh_path(path) do
71 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')