From 50aadc3d5cc35e5210cb12c4858ecfdba4df56b1 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 27 Nov 2020 13:42:28 -0600 Subject: [PATCH 1/2] shell_yes?/1 was not showing the correct message and always defaults to yes which is dangerous --- lib/mix/pleroma.ex | 6 ------ lib/mix/tasks/pleroma/user.ex | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index cd3f44074..7575f0ef8 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -98,12 +98,6 @@ def shell_prompt(prompt, defval \\ nil, defname \\ nil) do end end - def shell_yes?(message) do - if mix_shell?(), - do: Mix.shell().yes?("Continue?"), - else: shell_prompt(message, "Continue?") in ~w(Yn Y y) - end - def shell_info(message) do if mix_shell?(), do: Mix.shell().info(message), diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index a8d251411..ca9c8579f 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -60,7 +60,7 @@ def run(["new", nickname, email | rest]) do - admin: #{if(admin?, do: "true", else: "false")} """) - proceed? = assume_yes? or shell_yes?("Continue?") + proceed? = assume_yes? or shell_prompt("Continue?", "n") in ~w(Yn Y y) if proceed? do start_pleroma() From 657002e738adc5755ad2389b99cacd66f40c3715 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 4 Dec 2020 12:07:23 -0600 Subject: [PATCH 2/2] Answer new prompt interactively --- test/mix/tasks/pleroma/user_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/mix/tasks/pleroma/user_test.exs b/test/mix/tasks/pleroma/user_test.exs index ce819f815..ae0c50443 100644 --- a/test/mix/tasks/pleroma/user_test.exs +++ b/test/mix/tasks/pleroma/user_test.exs @@ -36,7 +36,7 @@ test "user is created" do unsaved = build(:user) # prepare to answer yes - send(self(), {:mix_shell_input, :yes?, true}) + send(self(), {:mix_shell_input, :prompt, "Y"}) Mix.Tasks.Pleroma.User.run([ "new", @@ -55,7 +55,7 @@ test "user is created" do assert_received {:mix_shell, :info, [message]} assert message =~ "user will be created" - assert_received {:mix_shell, :yes?, [message]} + assert_received {:mix_shell, :prompt, [message]} assert message =~ "Continue" assert_received {:mix_shell, :info, [message]} @@ -73,14 +73,14 @@ test "user is not created" do unsaved = build(:user) # prepare to answer no - send(self(), {:mix_shell_input, :yes?, false}) + send(self(), {:mix_shell_input, :prompt, "N"}) Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email]) assert_received {:mix_shell, :info, [message]} assert message =~ "user will be created" - assert_received {:mix_shell, :yes?, [message]} + assert_received {:mix_shell, :prompt, [message]} assert message =~ "Continue" assert_received {:mix_shell, :info, [message]}