25977f65656716b924a77dfe6b015ea5e70993c5
[akkoma] / lib / mix / tasks / pleroma / common.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Mix.Tasks.Pleroma.Common do
6 @doc "Common functions to be reused in mix tasks"
7 def start_pleroma do
8 Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
9 {:ok, _} = Application.ensure_all_started(:pleroma)
10 end
11
12 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
13 Keyword.get(options, opt) ||
14 case Mix.shell().prompt("#{prompt} [#{defname || defval}]") do
15 "\n" ->
16 case defval do
17 nil -> get_option(options, opt, prompt, defval)
18 defval -> defval
19 end
20
21 opt ->
22 opt |> String.trim()
23 end
24 end
25
26 def escape_sh_path(path) do
27 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
28 end
29 end