1
1
defmodule IEx.Options do
2
2
@ moduledoc """
3
- Provides an interface for changing options of the running IEx session.
3
+ Provides an interface for adjusting options of the running IEx session.
4
4
"""
5
5
6
6
@ supported_options [
@@ -12,8 +12,9 @@ defmodule IEx.Options do
12
12
The value is a keyword list that should have any of the following keys
13
13
specified. If any of the keys is omitted, that color is not changed.
14
14
15
- * enabled -- boolean value that allows to switch the colors
15
+ * enabled -- boolean value that allows for switching the coloring
16
16
on and off
17
+
17
18
* eval_result -- color for an expression's resulting value
18
19
* error -- color for error messages
19
20
* info -- color for various informational messages
@@ -43,15 +44,15 @@ defmodule IEx.Options do
43
44
end
44
45
45
46
def get ( name ) do
46
- raise ArgumentError , message: "Unknown IEx option #{ inspect name } "
47
+ raise_option ( name )
47
48
end
48
49
49
50
@ doc """
50
- Sets the value of the option `name` to `value`.
51
+ Sets the value for the option `name` to `value`.
51
52
52
- Returns option's previous value if in the case of success.
53
+ Returns option's previous value in the case of success.
53
54
54
- Raises if name is not a known option or if the value is invalid.
55
+ Raises if ` name` is not a known option or if the value is invalid.
55
56
"""
56
57
def set ( name , value )
57
58
@@ -63,7 +64,7 @@ defmodule IEx.Options do
63
64
end
64
65
65
66
def set ( :colors , _ ) do
66
- raise ArgumentError , message: "Expected colors to be a keyword list"
67
+ raise_value
67
68
end
68
69
69
70
def set ( :inspect , opts ) when is_list ( opts ) do
@@ -73,25 +74,26 @@ defmodule IEx.Options do
73
74
end
74
75
75
76
def set ( :inspect , _ ) do
76
- raise ArgumentError , message: "Expected opts to be a keyword list"
77
+ raise_value
77
78
end
78
79
79
80
def set ( name , _ ) do
80
- raise ArgumentError , message: "Unknown IEx option #{ inspect name } "
81
+ raise_option ( name )
81
82
end
82
83
83
84
@ doc """
84
- Returns a string with the option's description.
85
+ Returns a string with the option's description. Raises if `name` is not a
86
+ known option.
85
87
"""
86
88
def help ( name ) do
87
89
case @ supported_options [ name ] do
88
90
kv when is_list ( kv ) -> kv [ :doc ]
89
- nil -> :bad_option
91
+ nil -> raise_option ( name )
90
92
end
91
93
end
92
94
93
95
@ doc """
94
- Same as `help/1` but instead of returning a string, prints it to the console .
96
+ Same as `help/1` but instead of returning a string, prints it.
95
97
"""
96
98
def print_help ( name ) do
97
99
IO . write help ( name )
@@ -103,4 +105,12 @@ defmodule IEx.Options do
103
105
def list ( ) do
104
106
Enum . map @ supported_options , fn { k , _ } -> k end
105
107
end
108
+
109
+ defp raise_option ( name ) do
110
+ raise ArgumentError , message: "Unknown IEx option #{ inspect name } "
111
+ end
112
+
113
+ defp raise_value do
114
+ raise ArgumentError , message: "Expected the value to be a keyword list"
115
+ end
106
116
end
0 commit comments