From 62279cce0fed7d7199ff42c97242667c139faf19 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Mon, 9 Nov 2020 17:44:21 +0100 Subject: [PATCH] Fix relup cmd arguments and add validation relx:build_relup does not allow for undefined Release or ToVsn so we verify that they have been given on the command line before running relx:build_relup/4. --- src/rebar_relx.erl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/rebar_relx.erl b/src/rebar_relx.erl index 34a4dfa9..5f079176 100644 --- a/src/rebar_relx.erl +++ b/src/rebar_relx.erl @@ -49,10 +49,21 @@ do(Provider, State) -> case Provider of relup -> - ToVsn = proplists:get_value(relvsn, Opts, undefined), + {Release, ToVsn} = + %% hd/1 can't fail because --all is not a valid option to relup + case Releases of + [{Rel,Vsn}|_] when is_atom(Rel) -> + %% This is returned if --relvsn and --relname are given + {Rel, Vsn}; + [undefined|_] -> + erlang:error(?PRV_ERROR(unknown_release)); + [Rel|_] when is_atom(Rel) -> + erlang:error(?PRV_ERROR(unknown_vsn)) + end, + UpFromVsn = proplists:get_value(upfrom, Opts, undefined), - %% hd/1 can't fail because --all is not a valid option to relup - relx:build_relup(hd(Releases), ToVsn, UpFromVsn, RelxState); + + relx:build_relup(Release, ToVsn, UpFromVsn, RelxState); _ -> parallel_run(Provider, Releases, all_apps(State), RelxState) end, @@ -62,6 +73,10 @@ do(Provider, State) -> {ok, State}. -spec format_error(any()) -> iolist(). +format_error(unknown_release) -> + "Option --relname is missing"; +format_error(unknown_vsn) -> + "Option --relvsn is missing"; format_error(all_relup) -> "Option --all can not be applied to `relup` command"; format_error(Error) ->