diff --git a/src/cuttlefish_conf.erl b/src/cuttlefish_conf.erl index 72b7e48..957b3d7 100644 --- a/src/cuttlefish_conf.erl +++ b/src/cuttlefish_conf.erl @@ -77,7 +77,8 @@ file(Filename) -> {_, Values} = lists:unzip(Conf), case cuttlefish_error:filter(Values) of {errorlist, []} -> - remove_duplicates(Conf); + % expand any non-literal values (ie. included values) + expand_values(Filename, remove_duplicates(Conf)); {errorlist, ErrorList} -> NewErrorList = [ {error, {in_file, {Filename, E}}} || {error, E} <- ErrorList ], {errorlist, NewErrorList} @@ -98,6 +99,31 @@ fold_conf_files(Filename, Conf0) -> [], Conf0). +expand_values(Filename, Conf) -> + lists:map(fun({K, Value0}) -> + case re:split(Value0, "[$(<)]") of + [_, _, _, IncludeFilename0, _] -> + % this is a value of the format "$( + {K, re:replace(Value, "[\n\r]", "", [global, {return, list}])}; + {error, Reason} -> + throw({unable_to_open, IncludeFilename, Reason}) + end; + _ -> + % normal value, nothing to do + {K, Value0} + end + end, + Conf). + -spec generate([cuttlefish_mapping:mapping()]) -> [string()]. generate(Mappings) -> lists:foldl( @@ -391,6 +417,14 @@ included_dir_test() -> ]), lists:sort(Conf)), ok. +included_value_test() -> + Conf = file("test/included_value.conf"), + ?assertEqual(lists:sort([ + {["value1"],"42"}, + {["value2"], "43"} + ]), lists:sort(Conf)), + ok. + assert_no_output(Setting) -> Mapping = cuttlefish_mapping:parse( {mapping, diff --git a/test/included_value.conf b/test/included_value.conf new file mode 100644 index 0000000..ada8925 --- /dev/null +++ b/test/included_value.conf @@ -0,0 +1,2 @@ +value1 = $(