summaryrefslogtreecommitdiff
path: root/deps/gsms/src/gsms_lib.erl
blob: 187aefd4aa03ed857d57bfb64053a7059bb834d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-module(gsms_lib).

-export([get_opt/2,
	 get_opt/3]).

get_opt(K, Opts) when is_atom(K) ->
    case lists:keyfind(K, 1, Opts) of
	false  -> erlang:error({mandatory, K});
	{_, V} -> V
    end;
get_opt({K, Def}, Opts) ->
    get_opt(K, Opts, Def).

get_opt(K, Opts, Def) ->
    case lists:keyfind(K, 1, Opts) of
	false when is_function(Def, 0) ->
	    Def();
	false when Def == '$mandatory' ->
	    error({mandatory, K});
	false ->
	    Def;
	{_, V} ->
	    V
    end.