48c0c13464325f937801343c7cb9ad7a3fe4b381
[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 Mix.Task.run("app.start")
9 end
10
11 def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
12 Keyword.get(options, opt) ||
13 case Mix.shell().prompt("#{prompt} [#{defname || defval}]") do
14 "\n" ->
15 case defval do
16 nil -> get_option(options, opt, prompt, defval)
17 defval -> defval
18 end
19
20 opt ->
21 opt |> String.trim()
22 end
23 end
24
25 def escape_sh_path(path) do
26 ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
27 end
28 end