2018-12-23 20:05:55 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-12-07 05:12:39 +00:00
|
|
|
defmodule Mix.Tasks.Pleroma.Common do
|
2018-12-09 09:12:48 +00:00
|
|
|
@doc "Common functions to be reused in mix tasks"
|
2018-12-07 05:12:39 +00:00
|
|
|
def start_pleroma do
|
2019-06-07 10:37:20 +01:00
|
|
|
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
|
|
|
|
{:ok, _} = Application.ensure_all_started(:pleroma)
|
2018-12-07 05:12:39 +00:00
|
|
|
end
|
|
|
|
|
2018-12-07 06:46:13 +00:00
|
|
|
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
|
2018-12-07 05:12:39 +00:00
|
|
|
Keyword.get(options, opt) ||
|
2018-12-07 06:46:13 +00:00
|
|
|
case Mix.shell().prompt("#{prompt} [#{defname || defval}]") do
|
2018-12-07 05:12:39 +00:00
|
|
|
"\n" ->
|
2018-12-07 06:46:13 +00:00
|
|
|
case defval do
|
|
|
|
nil -> get_option(options, opt, prompt, defval)
|
|
|
|
defval -> defval
|
2018-12-07 05:12:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
opt ->
|
|
|
|
opt |> String.trim()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def escape_sh_path(path) do
|
|
|
|
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
|
|
|
|
end
|
|
|
|
end
|