Skip to content

Commit

Permalink
Merge pull request #188 from tsloughter/master
Browse files Browse the repository at this point in the history
fix for setting overrides with -a
  • Loading branch information
jwilberding committed May 24, 2014
2 parents 6a50af3 + f2864cb commit 69daf47
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/relx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ do(RootDir, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Configs) ->
-spec do(file:name(), atom(), string(), [goal()], [file:name()],
ec_cmd_log:log_level(), [file:name()], [{atom(), file:name()}], file:name() | undefined) ->
ok | error() | {ok, rlx_state:t()}.
do(RootDir, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Overrides, Config) ->
do(RootDir, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Overrides, Config) ->
do([{relname, RelName},
{relvsn, RelVsn},
{goals, Goals},
Expand Down Expand Up @@ -199,7 +199,7 @@ opt_spec_list() ->
"Verbosity level, maybe between 0 and 3"},
{dev_mode, $d, "dev-mode", {boolean, false},
"Symlink the applications and configuration into the release instead of copying"},
{override_app, $a, "override_app", string,
{override, $a, "override", string,
"Provide an app name and a directory to override in the form <appname>:<app directory>"},
{config, $c, "config", {string, ""}, "The path to a config file"},
{overlay_vars, undefined, "overlay_vars", string, "Path to a file of overlay variables"},
Expand Down Expand Up @@ -258,7 +258,7 @@ handle_output(_State, command_line, _) ->
handle_output(_State, api, Result) ->
Result.

run_providers(ConfigProvider, Providers, State0) ->
run_providers(ConfigProvider, Providers, State0) ->
case Providers of
[ConfigProvider | Rest] ->
%% IF the config provider is still the first provider do not run it
Expand Down
29 changes: 19 additions & 10 deletions src/rlx_cmd_args.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ args2state(Opts, Targets) ->
{ok, CommandLineConfig} ->
RelName = rlx_util:to_atom(proplists:get_value(relname, Opts, undefined)),
RelVsn = proplists:get_value(relvsn, Opts, undefined),
handle_config(Opts, AtomizedTargets,
handle_config(Opts, AtomizedTargets,
[{default_release, {RelName, RelVsn}} | CommandLineConfig])
end;
Error ->
Expand Down Expand Up @@ -131,8 +131,8 @@ validate_config(Config) ->
?RLX_ERROR({invalid_config_file, Config})
end.

run_creates(Opts) ->
try
run_creates(Opts) ->
try
Conf = lists:flatten(lists:foldl(fun(X, Acc) ->
[create(X, Opts) | Acc]
end, [], proplists:get_keys(Opts))),
Expand All @@ -141,15 +141,15 @@ run_creates(Opts) ->
throw:E ->
E
end.

create(log_level, Opts) ->
LogLevel = proplists:get_value(log_level, Opts, 0),
if
LogLevel >= 0, LogLevel =< 3 ->
{log, ec_cmd_log:new(LogLevel, command_line)};
true ->
throw(?RLX_ERROR({invalid_log_level, LogLevel}))
end;
end;
create(goal, Opts) ->
Goals = proplists:get_value(goals, Opts, []) ++
proplists:get_all_values(goal, Opts),
Expand All @@ -168,12 +168,21 @@ create(goals, Opts) ->
{ok, Specs} ->
{goals, Specs}
end;
create(override, Opts) ->
Overrides = proplists:get_value(overrides, Opts, []) ++
proplists:get_all_values(override, Opts),
case convert_overrides(Overrides, []) of
{ok, Overrides2} ->
{overrides, Overrides2};
Error ->
throw(Error)
end;
create(overrides, Opts) ->
Overrides = proplists:get_all_values(override, Opts) ++
proplists:get_value(overrides, Opts, []),
Overrides = proplists:get_value(overrides, Opts, []) ++
proplists:get_all_values(override, Opts),
case convert_overrides(Overrides, []) of
{ok, Overrides} ->
{overrides, Overrides};
{ok, Overrides2} ->
{overrides, Overrides2};
Error ->
throw(Error)
end;
Expand Down Expand Up @@ -275,7 +284,7 @@ convert_overrides([Override | Rest], Acc)
when erlang:is_list(Override); erlang:is_binary(Override) ->
case re:split(Override, ":") of
[AppName, AppDir] ->
convert_overrides(Rest, [{erlang:iolist_to_binary(AppName), AppDir} | Acc]);
convert_overrides(Rest, [{rlx_util:to_atom(AppName), AppDir} | Acc]);
_ ->
?RLX_ERROR({failed_to_parse_override, Override})
end;
Expand Down
4 changes: 3 additions & 1 deletion test/rlx_command_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ normal_passing_case(Config) ->
RelName = "foo-release",
RelVsn = "33.222",
CmdLine = ["-V", LogLevel, "-g",Goal1,"-g",Goal2, "-l", Lib1, "-l", Lib2,
"-n", RelName, "-v", RelVsn, "-o", Outdir],
"-n", RelName, "-v", RelVsn, "-o", Outdir, "-a", "lib1:"++binary_to_list(Lib1)],
{ok, {Opts, Targets}} = getopt:parse(relx:opt_spec_list(), CmdLine),
{ok, State} = rlx_cmd_args:args2state(Opts, Targets),
{ConfigProvider, {ok, State1}} = rlx_provider:new(rlx_prv_config, State),
{ok, State2} = rlx_provider:do(ConfigProvider, State1),
Overrides = rlx_state:overrides(State2),
?assertMatch([{lib1, Lib1}], Overrides),
?assertMatch([Lib1, Lib2],
rlx_state:lib_dirs(State2)),
?assertMatch(Outdir, rlx_state:base_output_dir(State2)),
Expand Down

0 comments on commit 69daf47

Please sign in to comment.