2019-01-03 11:34:31 +01:00
|
|
|
# Portions of this file are derived from Pleroma:
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
# Upstream: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/mix/tasks/pleroma/common.ex
|
|
|
|
|
|
|
|
defmodule Mix.Tasks.Mobilizon.Common do
|
2019-09-22 16:26:23 +02:00
|
|
|
@moduledoc """
|
|
|
|
Common functions to be reused in mix tasks
|
|
|
|
"""
|
2019-01-03 11:34:31 +01:00
|
|
|
|
|
|
|
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
|
|
|
|
display = if defname || defval, do: "#{prompt} [#{defname || defval}]", else: "#{prompt}"
|
|
|
|
|
|
|
|
Keyword.get(options, opt) ||
|
|
|
|
case Mix.shell().prompt(display) do
|
|
|
|
"\n" ->
|
|
|
|
case defval do
|
2019-09-22 16:26:23 +02:00
|
|
|
nil ->
|
|
|
|
get_option(options, opt, prompt, defval)
|
|
|
|
|
|
|
|
defval ->
|
|
|
|
defval
|
2019-01-03 11:34:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
opt ->
|
2019-09-22 16:26:23 +02:00
|
|
|
String.trim(opt)
|
2019-01-03 11:34:31 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-30 16:40:59 +02:00
|
|
|
def start_mobilizon do
|
|
|
|
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2019-07-30 16:40:59 +02:00
|
|
|
{:ok, _} = Application.ensure_all_started(:mobilizon)
|
|
|
|
end
|
|
|
|
|
2019-01-03 11:34:31 +01:00
|
|
|
def escape_sh_path(path) do
|
|
|
|
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
|
|
|
|
end
|
|
|
|
end
|