From 1d11c4cf11e27992c6b79731015456a954307e8f Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Fri, 7 Dec 2018 06:12:39 +0100 Subject: [PATCH 1/2] add common.ex --- lib/mix/tasks/pleroma/common.ex | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/mix/tasks/pleroma/common.ex diff --git a/lib/mix/tasks/pleroma/common.ex b/lib/mix/tasks/pleroma/common.ex new file mode 100644 index 000000000..2e246c4b5 --- /dev/null +++ b/lib/mix/tasks/pleroma/common.ex @@ -0,0 +1,24 @@ +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 + + def get_option(options, opt, prompt, def \\ nil, defname \\ nil) do + Keyword.get(options, opt) || + case Mix.shell().prompt("#{prompt} [#{defname || def}]") do + "\n" -> + case def do + nil -> get_option(options, opt, prompt, def) + def -> def + end + + opt -> + opt |> String.trim() + end + end + + def escape_sh_path(path) do + ~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(') + end +end From 08e10a70ec8752b30010389c0f5e14105fc58c3e Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 7 Dec 2018 09:46:13 +0300 Subject: [PATCH 2/2] Rename def to defval --- lib/mix/tasks/pleroma/common.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mix/tasks/pleroma/common.ex b/lib/mix/tasks/pleroma/common.ex index 2e246c4b5..06893af05 100644 --- a/lib/mix/tasks/pleroma/common.ex +++ b/lib/mix/tasks/pleroma/common.ex @@ -4,13 +4,13 @@ defmodule Mix.Tasks.Pleroma.Common do Mix.Task.run("app.start") end - def get_option(options, opt, prompt, def \\ nil, defname \\ nil) do + def get_option(options, opt, prompt, defval \\ nil, defname \\ nil) do Keyword.get(options, opt) || - case Mix.shell().prompt("#{prompt} [#{defname || def}]") do + case Mix.shell().prompt("#{prompt} [#{defname || defval}]") do "\n" -> - case def do - nil -> get_option(options, opt, prompt, def) - def -> def + case defval do + nil -> get_option(options, opt, prompt, defval) + defval -> defval end opt ->