Pleroma/lib/mix/tasks/pleroma/common.ex

25 lines
636 B
Elixir
Raw Normal View History

2018-12-07 06:12:39 +01:00
defmodule Mix.Tasks.Pleroma.Common do
@shortdoc "Common functions to be reused in mix tasks"
def start_pleroma do
Mix.Task.run("app.start")
end
2018-12-07 07:46:13 +01:00
def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do
2018-12-07 06:12:39 +01:00
Keyword.get(options, opt) ||
2018-12-07 07:46:13 +01:00
case Mix.shell().prompt("#{prompt} [#{defname || defval}]") do
2018-12-07 06:12:39 +01:00
"\n" ->
2018-12-07 07:46:13 +01:00
case defval do
nil -> get_option(options, opt, prompt, defval)
defval -> defval
2018-12-07 06:12:39 +01:00
end
opt ->
opt |> String.trim()
end
end
def escape_sh_path(path) do
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
end
end