aboutsummaryrefslogtreecommitdiffstats
path: root/src/rlx_config.erl
diff options
context:
space:
mode:
authorTristan Sloughter <[email protected]>2014-10-01 08:03:25 -0500
committerTristan Sloughter <[email protected]>2014-10-11 11:13:05 -0500
commite4849bd132b28ba1e1420686aadf8b2136c44fbd (patch)
tree6d37fc2e021e8a860056dbc2cb59361de132bc54 /src/rlx_config.erl
parent2604b7f0e9e11ee2fae17816499aba180b9b9683 (diff)
downloadrelx-e4849bd132b28ba1e1420686aadf8b2136c44fbd.tar.gz
relx-e4849bd132b28ba1e1420686aadf8b2136c44fbd.tar.bz2
relx-e4849bd132b28ba1e1420686aadf8b2136c44fbd.zip
support config passed in as proplist instead of filename
Diffstat (limited to 'src/rlx_config.erl')
-rw-r--r--src/rlx_config.erl28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/rlx_config.erl b/src/rlx_config.erl
index d4acb3c..dbfe1c6 100644
--- a/src/rlx_config.erl
+++ b/src/rlx_config.erl
@@ -97,20 +97,26 @@ parent_dir([_H], Acc) ->
parent_dir([H | T], Acc) ->
parent_dir(T, [H | Acc]).
--spec load_config(file:filename(), rlx_state:t()) ->
+-spec load_config(file:filename() | proplists:proplist(), rlx_state:t()) ->
{ok, rlx_state:t()} | relx:error().
load_config(ConfigFile, State) ->
{ok, CurrentCwd} = file:get_cwd(),
- ok = file:set_cwd(filename:dirname(ConfigFile)),
- Result = case file:consult(ConfigFile) of
- {error, Reason} ->
- ?RLX_ERROR({consult, ConfigFile, Reason});
- {ok, Terms} ->
- CliTerms = rlx_state:cli_args(State),
- lists:foldl(fun load_terms/2, {ok, State}, merge_configs(CliTerms, Terms))
- end,
- ok = file:set_cwd(CurrentCwd),
- Result.
+ case filelib:is_regular(ConfigFile) of
+ true ->
+ ok = file:set_cwd(filename:dirname(ConfigFile)),
+ Result = case file:consult(ConfigFile) of
+ {error, Reason} ->
+ ?RLX_ERROR({consult, ConfigFile, Reason});
+ {ok, Terms} ->
+ CliTerms = rlx_state:cli_args(State),
+ lists:foldl(fun load_terms/2, {ok, State}, merge_configs(CliTerms, Terms))
+ end,
+ ok = file:set_cwd(CurrentCwd),
+ Result;
+ false ->
+ CliTerms = rlx_state:cli_args(State),
+ lists:foldl(fun load_terms/2, {ok, State}, merge_configs(CliTerms, ConfigFile))
+ end.
-spec load_terms(term(), {ok, rlx_state:t()} | relx:error()) ->
{ok, rlx_state:t()} | relx:error().