Skip to content

Commit

Permalink
Merge pull request #29 from tsloughter/master
Browse files Browse the repository at this point in the history
Tar action, multiple actions on cli and rename release dir
  • Loading branch information
ericbmerritt committed Sep 12, 2013
2 parents 98c2370 + 8bc6e0a commit 73536c5
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/relx.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{application, relx,
[{description, "Release assembler for Erlang/OTP Releases"},
{vsn, "0.0.5"},
{vsn, "semver"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib, getopt, erlware_commons]}]}.
12 changes: 6 additions & 6 deletions src/relx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ do(RootDir, RelName, RelVsn, Goals, LibDirs, LogLevel, OutputDir, Overrides, Con
-spec do(proplists:proplist(), [string()]) ->
ok | error() | {ok, rlx_state:t()}.
do(Opts, NonOpts) ->
case rlx_cmd_args:args2state(Opts, NonOpts) of
{ok, State} ->
run_relx_process(State);
Error={error, _} ->
Error
end.
case rlx_cmd_args:args2state(Opts, NonOpts) of
{ok, State} ->
run_relx_process(State);
Error={error, _} ->
Error
end.

-spec opt_spec_list() -> [getopt:option_spec()].
opt_spec_list() ->
Expand Down
43 changes: 24 additions & 19 deletions src/rlx_cmd_args.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,21 @@
-spec args2state([getopt:option()], [string()]) ->
{ok, {rlx_state:t(), [string()]}} |
relx:error().
args2state(Opts, Target)
when erlang:length(Target) == 0; erlang:length(Target) == 1 ->
args2state(Opts, Targets) ->
RelName = rlx_util:to_atom(proplists:get_value(relname, Opts, undefined)),
RelVsn = proplists:get_value(relvsn, Opts, undefined),
case convert_target(Target) of
{ok, AtomizedTarget} ->
case convert_targets(Targets) of
{ok, AtomizedTargets} ->
case create_log(Opts, [{relname, RelName},
{relvsn, RelVsn}]) of
Error = {error, _} ->
Error;
{ok, CommandLineConfig} ->
handle_config(Opts, AtomizedTarget, CommandLineConfig)
handle_config(Opts, AtomizedTargets, CommandLineConfig)
end;
Error ->
Error
end;
args2state(_Opts, Targets) ->
?RLX_ERROR({invalid_targets, Targets}).
end.

-spec format_error(Reason::term()) -> iolist().
format_error({invalid_targets, Targets}) ->
Expand Down Expand Up @@ -88,25 +85,33 @@ format_error({invalid_target, Target}) ->
%%%===================================================================
%%% Internal Functions
%%%===================================================================
-spec handle_config([getopt:option()], atom(), proplists:proplist()) ->
-spec handle_config([getopt:option()], [atom()], proplists:proplist()) ->
{ok, {rlx_state:t(), [string()]}} |
relx:error().
handle_config(Opts, Target, CommandLineConfig) ->
handle_config(Opts, Targets, CommandLineConfig) ->
case validate_config(proplists:get_value(config, Opts, [])) of
Error = {error, _} ->
Error;
{ok, Config} ->
{ok, rlx_state:new([{config, Config} | CommandLineConfig], Target)}
{ok, rlx_state:new([{config, Config} | CommandLineConfig], Targets)}
end.

-spec convert_target([string()]) -> {ok, release | relup} | relx:error().
convert_target([]) ->
{ok, release};
convert_target(["release"]) ->
{ok, release};
convert_target(["relup"]) ->
{ok, relup};
convert_target(Target) ->
-spec convert_targets([string()]) -> {ok, release | relup} | relx:error().
convert_targets(Targets) ->
convert_targets(Targets, []).

-spec convert_targets([string()], [string()]) -> {ok, release | relup} | relx:error().
convert_targets([], []) ->
{ok, [release]};
convert_targets([], Acc) ->
{ok, Acc};
convert_targets(["release" | T], Acc) ->
convert_targets(T, [release | Acc]);
convert_targets(["relup" | T], Acc) ->
convert_targets(T, [relup | Acc]);
convert_targets(["tar" | T], Acc) ->
convert_targets(T, [tar | Acc]);
convert_targets([Target | _T], _Acc) ->
?RLX_ERROR({invalid_target, Target}).

-spec validate_config(file:filename() | undefined) ->
Expand Down
16 changes: 8 additions & 8 deletions src/rlx_goal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

-compile(export_all).
-spec file(file:name()) -> any().
file(Filename) -> {ok, Bin} = file:read_file(Filename), parse(Bin).
file(Filename) -> case file:read_file(Filename) of {ok,Bin} -> parse(Bin); Err -> Err end.

-spec parse(binary() | list()) -> any().
parse(List) when is_list(List) -> parse(list_to_binary(List));
Expand All @@ -18,7 +18,7 @@ parse(Input) when is_binary(Input) ->
release_memo(), Result.

'constraint'(Input, Index) ->
p(Input, Index, 'constraint', fun(I,D) -> (p_choose([p_seq([p_optional(fun 'ws'/2), fun 'app_name'/2, p_optional(fun 'ws'/2), fun 'between_op'/2, p_optional(fun 'ws'/2), fun 'version'/2, p_optional(fun 'ws'/2), p_string(<<",">>), p_optional(fun 'ws'/2), fun 'version'/2, p_optional(fun 'ws'/2), p_not(p_anything())]), p_seq([p_optional(fun 'ws'/2), fun 'app_name'/2, p_optional(fun 'ws'/2), fun 'constraint_op'/2, p_optional(fun 'ws'/2), fun 'version'/2, p_optional(fun 'ws'/2), p_not(p_anything())]), p_seq([p_optional(fun 'ws'/2), fun 'app_name'/2, p_optional(fun 'ws'/2), p_not(p_anything())])]))(I,D) end, fun(Node, _Idx) ->
p(Input, Index, 'constraint', fun(I,D) -> (p_choose([p_seq([p_optional(fun 'ws'/2), fun 'app_name'/2, p_optional(fun 'ws'/2), fun 'between_op'/2, p_optional(fun 'ws'/2), fun 'version'/2, p_optional(fun 'ws'/2), p_string(<<",">>), p_optional(fun 'ws'/2), fun 'version'/2, p_optional(fun 'ws'/2), p_not(p_anything())]), p_seq([p_optional(fun 'ws'/2), fun 'app_name'/2, p_optional(fun 'ws'/2), fun 'constraint_op'/2, p_optional(fun 'ws'/2), fun 'version'/2, p_optional(fun 'ws'/2), p_not(p_anything())]), p_seq([p_optional(fun 'ws'/2), fun 'app_name'/2, p_optional(fun 'ws'/2), p_not(p_anything())])]))(I,D) end, fun(Node, _Idx) ->
case Node of
[_,AppName,_, _] ->
{ok, AppName};
Expand All @@ -39,30 +39,30 @@ parse(Input) when is_binary(Input) ->
end).

'ws'(Input, Index) ->
p(Input, Index, 'ws', fun(I,D) -> (p_charclass(<<"[\s\t\n\s\r]">>))(I,D) end, fun(Node, Idx) -> transform('ws', Node, Idx) end).
p(Input, Index, 'ws', fun(I,D) -> (p_charclass(<<"[\s\t\n\s\r]">>))(I,D) end, fun(Node, Idx) ->transform('ws', Node, Idx) end).

'app_name'(Input, Index) ->
p(Input, Index, 'app_name', fun(I,D) -> (p_one_or_more(p_charclass(<<"[a-zA-Z0-9_]">>)))(I,D) end, fun(Node, _Idx) -> erlang:list_to_atom(erlang:binary_to_list(erlang:iolist_to_binary(Node))) end).
p(Input, Index, 'app_name', fun(I,D) -> (p_one_or_more(p_charclass(<<"[a-zA-Z0-9_]">>)))(I,D) end, fun(Node, _Idx) -> erlang:list_to_atom(erlang:binary_to_list(erlang:iolist_to_binary(Node))) end).

'between_op'(Input, Index) ->
p(Input, Index, 'between_op', fun(I,D) -> (p_seq([p_string(<<":">>), p_optional(fun 'ws'/2), p_choose([p_string(<<"btwn">>), p_string(<<"between">>)]), p_optional(fun 'ws'/2), p_string(<<":">>)]))(I,D) end, fun(Node, _Idx) -> case Node of
p(Input, Index, 'between_op', fun(I,D) -> (p_seq([p_string(<<":">>), p_optional(fun 'ws'/2), p_choose([p_string(<<"btwn">>), p_string(<<"between">>)]), p_optional(fun 'ws'/2), p_string(<<":">>)]))(I,D) end, fun(Node, _Idx) -> case Node of
[C,_,Op,_,C] -> erlang:iolist_to_binary([C,Op,C]);
_ -> Node
end
end).

'constraint_op'(Input, Index) ->
p(Input, Index, 'constraint_op', fun(I,D) -> (p_choose([p_string(<<"=">>), p_string(<<"-">>), p_string(<<"<=">>), p_string(<<"<">>), p_string(<<"~>">>), p_string(<<">=">>), p_string(<<">">>), fun 'word_constraint_op'/2, p_string(<<":">>)]))(I,D) end, fun(Node, Idx) -> transform('constraint_op', Node, Idx) end).
p(Input, Index, 'constraint_op', fun(I,D) -> (p_choose([p_string(<<"=">>), p_string(<<"-">>), p_string(<<"<=">>), p_string(<<"<">>), p_string(<<"~>">>), p_string(<<">=">>), p_string(<<">">>), fun 'word_constraint_op'/2, p_string(<<":">>)]))(I,D) end, fun(Node, Idx) ->transform('constraint_op', Node, Idx) end).

'word_constraint_op'(Input, Index) ->
p(Input, Index, 'word_constraint_op', fun(I,D) -> (p_seq([p_string(<<":">>), p_optional(fun 'ws'/2), p_choose([p_string(<<"gte">>), p_string(<<"lte">>), p_string(<<"gt">>), p_string(<<"lt">>), p_string(<<"pes">>)]), p_optional(fun 'ws'/2), p_string(<<":">>)]))(I,D) end, fun(Node, _Idx) -> case Node of
p(Input, Index, 'word_constraint_op', fun(I,D) -> (p_seq([p_string(<<":">>), p_optional(fun 'ws'/2), p_choose([p_string(<<"gte">>), p_string(<<"lte">>), p_string(<<"gt">>), p_string(<<"lt">>), p_string(<<"pes">>)]), p_optional(fun 'ws'/2), p_string(<<":">>)]))(I,D) end, fun(Node, _Idx) -> case Node of
[C,_,Op,_,C] -> erlang:iolist_to_binary([C,Op,C]);
_ -> Node
end
end).

'version'(Input, Index) ->
p(Input, Index, 'version', fun(I,D) -> (p_one_or_more(p_charclass(<<"[0-9a-zA-Z-+.]">>)))(I,D) end, fun(Node, Idx) -> transform('version', Node, Idx) end).
p(Input, Index, 'version', fun(I,D) -> (p_one_or_more(p_charclass(<<"[0-9a-zA-Z-+.]">>)))(I,D) end, fun(Node, Idx) ->transform('version', Node, Idx) end).


transform(_,Node,_Index) -> Node.
Expand Down
Loading

0 comments on commit 73536c5

Please sign in to comment.