From 306d584398696d08e3ca26d6864fa71cdcfe4012 Mon Sep 17 00:00:00 2001 From: Eric Date: Sun, 30 Dec 2012 17:34:25 -0500 Subject: only allow relcool to take a single config --- src/rcl_cmd_args.erl | 13 +++++++++---- src/relcool.erl | 2 +- test/rclt_command_SUITE.erl | 3 +-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/rcl_cmd_args.erl b/src/rcl_cmd_args.erl index dc176be..3bb9f41 100644 --- a/src/rcl_cmd_args.erl +++ b/src/rcl_cmd_args.erl @@ -34,7 +34,8 @@ relcool:error(). args2state({error, Detail}) -> ?RCL_ERROR({opt_parse, Detail}); -args2state({ok, {Opts, Targets}}) -> +args2state({ok, {Opts, Target}}) + when erlang:length(Target) == 0; erlang:length(Target) == 1 -> RelName = proplists:get_value(relname, Opts, undefined), RelVsn = proplists:get_value(relvsn, Opts, undefined), case create_log(Opts, @@ -43,15 +44,19 @@ args2state({ok, {Opts, Targets}}) -> Error = {error, _} -> Error; {ok, CommandLineConfig} -> - case validate_configs(Targets) of + case validate_configs(Target) of Error = {error, _} -> Error; {ok, Configs} -> - {ok, {rcl_state:new(CommandLineConfig, Configs), Configs}} + {ok, rcl_state:new(CommandLineConfig, Configs)} end - end. + end; +args2state({ok, {_Opts, Targets}}) -> + ?RCL_ERROR({invalid_targets, Targets}). -spec format_error(Reason::term()) -> iolist(). +format_error({invalid_targets, Targets}) -> + io_lib:format("One config must be specified! not ~p~n", [Targets]); format_error({opt_parse, {invalid_option, Opt}}) -> io_lib:format("invalid option ~s~n", [Opt]); format_error({opt_parse, Arg}) -> diff --git a/src/relcool.erl b/src/relcool.erl index c6747ca..fb17711 100644 --- a/src/relcool.erl +++ b/src/relcool.erl @@ -43,7 +43,7 @@ main(Args) -> OptSpecList = opt_spec_list(), case rcl_cmd_args:args2state(getopt:parse(OptSpecList, Args)) of - {ok, {State, _Target}} -> + {ok, State} -> run_relcool_process(rcl_state:caller(State, command_line)); Error={error, _} -> report_error(rcl_state:caller(rcl_state:new([], []), diff --git a/test/rclt_command_SUITE.erl b/test/rclt_command_SUITE.erl index 1c6accf..bd99da0 100644 --- a/test/rclt_command_SUITE.erl +++ b/test/rclt_command_SUITE.erl @@ -58,8 +58,7 @@ normal_passing_case(Config) -> RelVsn = "33.222", CmdLine = ["-V", LogLevel, "-g",Goal1,"-g",Goal2, "-l", Lib1, "-l", Lib2, "-n", RelName, "-v", RelVsn, "-o", Outdir], - {ok, {State, Target}} = rcl_cmd_args:args2state(getopt:parse(relcool:opt_spec_list(), CmdLine)), - ?assertMatch([], Target), + {ok, State} = rcl_cmd_args:args2state(getopt:parse(relcool:opt_spec_list(), CmdLine)), ?assertMatch([Lib1, Lib2], rcl_state:lib_dirs(State)), ?assertMatch(Outdir, rcl_state:output_dir(State)), -- cgit v1.2.3