diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rcl_cmd_args.erl | 31 | ||||
-rw-r--r-- | src/rcl_state.erl | 20 | ||||
-rw-r--r-- | src/relcool.erl | 3 |
3 files changed, 46 insertions, 8 deletions
diff --git a/src/rcl_cmd_args.erl b/src/rcl_cmd_args.erl index 454e762..f8918c2 100644 --- a/src/rcl_cmd_args.erl +++ b/src/rcl_cmd_args.erl @@ -45,12 +45,39 @@ args2state({ok, {Opts, Targets}}) -> Error = {error, _} -> Error; {ok, CommandLineConfig} -> - {ok, {rcl_state:new(CommandLineConfig), Targets}} + case validate_configs(Targets) of + Error = {error, _} -> + Error; + {ok, Configs} -> + {ok, {rcl_state:new(CommandLineConfig, Configs), Configs}} + end end. %%%=================================================================== %%% Internal Functions %%%=================================================================== +-spec validate_configs([file:filename()]) -> + {ok, [file:filename()]} | {error, Reason::term()}. +validate_configs(Configs) -> + Result = + lists:foldl(fun(_Config, Err = {error, _}) -> + Err; + (Config, Acc) -> + case filelib:is_regular(Config) of + true -> + [filename:absname(Config) | Acc]; + false -> + {error, {invalid_config_file, Config}} + end + end, [], Configs), + case Result of + {error, _} -> + Result; + _ -> + %% Order may be important so lets make sure they remain in the same + %% order they came in as + {ok, lists:reverse(Result)} + end. -spec create_log([getopt:option()], rcl_state:cmd_args()) -> {ok, rcl_state:cmd_args()} | {error, Reason::term()}. @@ -110,7 +137,7 @@ create_lib_dirs(Opts, Acc) -> Error = {error, _} -> Error; ok -> - {ok, [{lib_dirs, Dirs} | Acc]} + {ok, [{lib_dirs, [filename:absname(Dir) || Dir <- Dirs]} | Acc]} end. -spec check_lib_dirs([string()]) -> ok | {error, {Reason::atom(), Dir::string()}}. diff --git a/src/rcl_state.erl b/src/rcl_state.erl index 3a61e58..1b25ce3 100644 --- a/src/rcl_state.erl +++ b/src/rcl_state.erl @@ -23,11 +23,12 @@ %%% have a more mutable api. -module(rcl_state). --export([new/1, +-export([new/2, log/1, output_dir/1, lib_dirs/1, goals/1, + config_files/1, format/1, format/2]). @@ -37,6 +38,7 @@ -record(?MODULE, {log :: rcl_log:t(), output_dir :: file:name(), lib_dirs=[] :: [file:name()], + config_files=[] :: [file:filename()], goals=[] :: [depsolver:constraint()]}). %%============================================================================ @@ -50,11 +52,12 @@ %% API %%============================================================================ %% @doc Create a new 'log level' for the system --spec new(proplists:proplist()) -> t(). -new(PropList) when erlang:is_list(PropList) -> +-spec new(proplists:proplist(), [file:filename()]) -> t(). +new(PropList, Targets) when erlang:is_list(PropList) -> #?MODULE{log = proplists:get_value(log, PropList, rcl_log:new(error)), output_dir=proplists:get_value(output_dir, PropList, ""), lib_dirs=proplists:get_value(lib_dirs, PropList, []), + config_files=Targets, goals=proplists:get_value(goals, PropList, [])}. %% @doc get the current log state for the system @@ -74,16 +77,23 @@ lib_dirs(#?MODULE{lib_dirs=LibDir}) -> goals(#?MODULE{goals=TS}) -> TS. +-spec config_files(t()) -> [file:filename()]. +config_files(#?MODULE{config_files=ConfigFiles}) -> + ConfigFiles. + -spec format(t()) -> iolist(). format(Mod) -> format(Mod, 0). -spec format(t(), non_neg_integer()) -> iolist(). -format(#?MODULE{log=LogState, output_dir=OutDir, lib_dirs=LibDirs, goals=Goals}, +format(#?MODULE{log=LogState, output_dir=OutDir, lib_dirs=LibDirs, + goals=Goals, config_files=ConfigFiles}, Indent) -> [rcl_util:indent(Indent), <<"state:\n">>, rcl_util:indent(Indent + 1), <<"log: ">>, rcl_log:format(LogState), <<",\n">>, + rcl_util:indent(Indent + 1), "config files: \n", + [[rcl_util:indent(Indent + 2), ConfigFile, ",\n"] || ConfigFile <- ConfigFiles], rcl_util:indent(Indent + 1), "goals: \n", [[rcl_util:indent(Indent + 2), depsolver:format_constraint(Goal), ",\n"] || Goal <- Goals], rcl_util:indent(Indent + 1), "output_dir: ", OutDir, "\n", @@ -99,7 +109,7 @@ format(#?MODULE{log=LogState, output_dir=OutDir, lib_dirs=LibDirs, goals=Goals}, new_test() -> LogState = rcl_log:new(error), - RCLState = new([{log, LogState}]), + RCLState = new([{log, LogState}], []), ?assertMatch(LogState, log(RCLState)). -endif. diff --git a/src/relcool.erl b/src/relcool.erl index f8a9bbd..2284d29 100644 --- a/src/relcool.erl +++ b/src/relcool.erl @@ -31,7 +31,6 @@ %%============================================================================ -spec main([string()]) -> ok. main(Args) -> - io:format("~p~n", [Args]), OptSpecList = opt_spec_list(), case rcl_cmd_args:args2state(getopt:parse(OptSpecList, Args)) of {ok, {State, _Target}} -> @@ -90,6 +89,8 @@ to_error({error,{invalid_option_arg, Arg}}) -> {log_level, LogLevel} -> io_lib:format("Invalid Library Directory argument -n ~p~n", [LogLevel]) end; +to_error({error, {invalid_config_file, Config}}) -> + io_lib:format("Invalid configuration file specified: ~s", [Config]); to_error({error, {failed_to_parse, Spec}}) -> io_lib:format("Unable to parse spec ~s", [Spec]); to_error({error, {unable_to_create_output_dir, OutputDir}}) -> |