2020-10-30 12:10:07 +00:00
|
|
|
-module(ct_helper).
|
|
|
|
|
|
|
|
-export([with_config/3]).
|
|
|
|
|
|
|
|
-export([get_temp_dir/0]).
|
|
|
|
-export([get_env/1]).
|
|
|
|
|
|
|
|
-type config() :: [{atom(), term()}].
|
|
|
|
|
|
|
|
-export_type([config/0]).
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2021-02-04 14:23:35 +00:00
|
|
|
-spec with_config(atom(), config(), fun((_) -> R)) -> R | undefined.
|
2020-10-30 12:10:07 +00:00
|
|
|
with_config(Name, C, Fun) ->
|
|
|
|
case lists:keyfind(Name, 1, C) of
|
|
|
|
{_, V} -> Fun(V);
|
2021-02-04 14:23:35 +00:00
|
|
|
false -> undefined
|
2020-10-30 12:10:07 +00:00
|
|
|
end.
|
|
|
|
|
2021-02-04 14:23:35 +00:00
|
|
|
-spec get_temp_dir() -> file:filename_all().
|
2020-10-30 12:10:07 +00:00
|
|
|
get_temp_dir() ->
|
2021-02-04 14:23:35 +00:00
|
|
|
hd(
|
|
|
|
genlib_list:compact([
|
|
|
|
get_env("TMPDIR"),
|
|
|
|
get_env("TEMP"),
|
|
|
|
get_env("TMP"),
|
|
|
|
"/tmp"
|
|
|
|
])
|
|
|
|
).
|
|
|
|
|
|
|
|
-spec get_env(string()) -> string() | undefined.
|
2020-10-30 12:10:07 +00:00
|
|
|
get_env(Name) ->
|
|
|
|
case os:getenv(Name) of
|
|
|
|
V when is_list(V) ->
|
|
|
|
V;
|
|
|
|
false ->
|
|
|
|
undefined
|
|
|
|
end.
|