Skip to content

Commit baec3e2

Browse files
committedMar 25, 2018
Add option to make awnsers to case sensitive
1 parent 79ea5dd commit baec3e2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed
 

‎lib/loki/shell.ex

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ defmodule Loki.Shell do
1717
Ask user input with given message. Returns tuple with parsed options.
1818
"""
1919
@spec ask(String.t) :: {List.t, List.t, List.t}
20-
def ask(message) when is_input(message) do
21-
args = format(IO.gets message)
20+
def ask(message, opts \\ [])
21+
def ask(message, opts) when is_input(message) do
22+
args = format(IO.gets(message), opts)
2223
OptionParser.parse([args])
2324
end
2425

25-
@spec ask(any) :: none()
26-
def ask(_any), do: raise ArgumentError, message: "Invalid argument, accept String or List!"
26+
@spec ask(any, any) :: none()
27+
def ask(_message, _ops), do: raise ArgumentError, message: "Invalid argument, accept String or List!"
2728

2829

2930
@doc """
@@ -219,6 +220,8 @@ defmodule Loki.Shell do
219220

220221

221222
@spec format(String.t) :: String.t
222-
defp format(input), do: String.replace(input, "\n", "") |> String.downcase
223+
defp format(input, opts \\ [])
224+
defp format(input, [sensitive: true]), do: String.replace(input, "\n", "")
225+
defp format(input, _opts), do: String.replace(input, "\n", "") |> String.downcase
223226
end
224227

‎test/loki/shell_test.exs

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ defmodule Loki.ShellTest do
1515
assert_received {[], ["answer"], []}
1616
end
1717

18+
test "#ask sensitive input" do
19+
assert capture_io("AnSwEr", fn ->
20+
awnser = ask("Test question?", sensitive: true)
21+
send self(), awnser
22+
end) == "Test question?"
23+
24+
assert_received {[], ["AnSwEr"], []}
25+
end
26+
1827
test "#yes? yes input" do
1928
assert capture_io("yes", fn ->
2029
awnser = yes?("Test question?")

0 commit comments

Comments
 (0)
Please sign in to comment.