Skip to content

Commit 3bad31d

Browse files
pmeinhardtbrienw
authored andcommitted
Refactor verbosity checks (#215)
* Refactor verbosity checks * Replace `x not in y` with `not(x in y)`
1 parent a33ac9b commit 3bad31d

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

lib/ui.ex

+9-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ defmodule Bootleg.UI do
44
a configured verbosity level.
55
"""
66

7+
@verbosities [:error, :warning, :info, :debug]
8+
79
@doc """
810
Simple wrapper around IO.puts
911
"""
@@ -67,24 +69,15 @@ defmodule Bootleg.UI do
6769
validate_verbosity setting || Application.get_env(:bootleg, :verbosity, :info)
6870
end
6971

70-
defp validate_verbosity(verbosity)
71-
defp validate_verbosity(:warning), do: :warning
72-
defp validate_verbosity(:debug), do: :debug
73-
defp validate_verbosity(:silent), do: :silent
72+
defp validate_verbosity(verbosity) when verbosity in @verbosities, do: verbosity
7473
defp validate_verbosity(_), do: :info
7574

76-
defp verbosity_includes(setting, level)
77-
defp verbosity_includes(:info, :info), do: true
78-
defp verbosity_includes(:info, :warning), do: true
79-
defp verbosity_includes(:info, :error), do: true
80-
defp verbosity_includes(:warning, :warning), do: true
81-
defp verbosity_includes(:warning, :error), do: true
82-
defp verbosity_includes(:error, :error), do: true
83-
defp verbosity_includes(:debug, :info), do: true
84-
defp verbosity_includes(:debug, :warning), do: true
85-
defp verbosity_includes(:debug, :debug), do: true
86-
defp verbosity_includes(:debug, :error), do: true
87-
defp verbosity_includes(_, _), do: false
75+
defp verbosity_includes(setting, _) when not(setting in @verbosities), do: false
76+
defp verbosity_includes(_, level) when not(level in @verbosities), do: false
77+
defp verbosity_includes(setting, level) do
78+
index = fn value -> Enum.find_index(@verbosities, &(&1 == value)) end
79+
index.(setting) >= index.(level)
80+
end
8881

8982
### SSH formatting functions
9083

0 commit comments

Comments
 (0)