diff options
author | Tristan Sloughter <[email protected]> | 2014-10-01 08:03:25 -0500 |
---|---|---|
committer | Tristan Sloughter <[email protected]> | 2014-10-11 11:13:05 -0500 |
commit | e4849bd132b28ba1e1420686aadf8b2136c44fbd (patch) | |
tree | 6d37fc2e021e8a860056dbc2cb59361de132bc54 /src | |
parent | 2604b7f0e9e11ee2fae17816499aba180b9b9683 (diff) | |
download | relx-e4849bd132b28ba1e1420686aadf8b2136c44fbd.tar.gz relx-e4849bd132b28ba1e1420686aadf8b2136c44fbd.tar.bz2 relx-e4849bd132b28ba1e1420686aadf8b2136c44fbd.zip |
support config passed in as proplist instead of filename
Diffstat (limited to 'src')
-rw-r--r-- | src/relx.erl | 6 | ||||
-rw-r--r-- | src/rlx_cmd_args.erl | 4 | ||||
-rw-r--r-- | src/rlx_config.erl | 28 | ||||
-rw-r--r-- | src/rlx_prv_overlay.erl | 7 | ||||
-rw-r--r-- | src/rlx_state.erl | 4 |
5 files changed, 32 insertions, 17 deletions
diff --git a/src/relx.erl b/src/relx.erl index e9867a9..37918be 100644 --- a/src/relx.erl +++ b/src/relx.erl @@ -21,6 +21,7 @@ -module(relx). -export([main/1, + main/2, do/2, do/7, do/8, @@ -44,6 +45,9 @@ %%============================================================================ -spec main([string()]) -> ok | error() | {ok, rlx_state:t()}. main(Args) -> + main([], Args). + +main(ApiOptions, Args) -> OptSpecList = opt_spec_list(), Result = case getopt:parse(OptSpecList, Args) of {ok, {Options, NonOptions}} -> @@ -58,7 +62,7 @@ main(Args) -> usage(); false -> application:start(relx), - do([{caller, command_line} | Options], NonOptions) + do(ApiOptions++[{caller, command_line} | Options], NonOptions) end end; {error, Detail} -> diff --git a/src/rlx_cmd_args.erl b/src/rlx_cmd_args.erl index e117d8e..84aeca5 100644 --- a/src/rlx_cmd_args.erl +++ b/src/rlx_cmd_args.erl @@ -69,7 +69,7 @@ format_error({invalid_option_arg, Arg}) -> io_lib:format("Invalid code path argument -n ~p~n", [Path]) end; format_error({invalid_config_file, Config}) -> - io_lib:format("Invalid configuration file specified: ~s", [Config]); + io_lib:format("Invalid configuration file specified: ~p", [Config]); format_error({invalid_caller, Caller}) -> io_lib:format("Invalid caller specified: ~s", [Caller]); format_error({failed_to_parse, Spec}) -> @@ -128,7 +128,7 @@ validate_config(Config) -> true -> {ok, filename:absname(Config)}; false -> - ?RLX_ERROR({invalid_config_file, Config}) + {ok, Config} end. run_creates(Opts) -> 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(). diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl index 4cbbf31..f7e2be8 100644 --- a/src/rlx_prv_overlay.erl +++ b/src/rlx_prv_overlay.erl @@ -377,7 +377,12 @@ get_relative_root(State) -> [] -> rlx_state:root_dir(State); Config -> - filename:dirname(Config) + case filelib:is_regular(Config) of + true -> + filename:dirname(Config); + false -> + rlx_state:root_dir(State) + end end. -spec is_directory(file:name(), file:name()) -> boolean(). diff --git a/src/rlx_state.erl b/src/rlx_state.erl index 71b96f3..a25c60f 100644 --- a/src/rlx_state.erl +++ b/src/rlx_state.erl @@ -216,11 +216,11 @@ goals(#state_t{goals=TS}) -> goals(State, Goals) -> State#state_t{goals=Goals}. --spec config_file(t()) -> file:filename() | undefined. +-spec config_file(t()) -> file:filename() | proplists:proplist() | undefined. config_file(#state_t{config_file=ConfigFiles}) -> ConfigFiles. --spec config_file(t(), file:filename() | undefined) -> t(). +-spec config_file(t(), file:filename() | proplists:proplist() | undefined) -> t(). config_file(State, ConfigFiles) -> State#state_t{config_file=ConfigFiles}. |