Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/cuttlefish_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

-export([
conf_get_value/2,
conf_get_value/3,
replace_proplist_value/3,
variable_starts_with/2,
filter_by_variable_starts_with/2,
Expand All @@ -42,10 +43,15 @@
%% @doc it's a wrapper for proplists:get_value, a convenience function
%% for schema writers to not have to use [] notation for varibales
-spec conf_get_value(string()|[string()], [{[string()], any()}]) -> any().
conf_get_value([H|_T]=Variable, ConfigProplist) when is_list(H) ->
proplists:get_value(Variable, ConfigProplist);
conf_get_value(Variable, ConfigProplist) ->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simplify this by having the 2-arity version call the 3-arity version with the third argument of undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, that almost seems "too" correct. will do.

conf_get_value(tokenize_variable_key(Variable), ConfigProplist).
conf_get_value(Variable, ConfigProplist, undefined).

-spec conf_get_value(string()|[string()], [{[string()], any()}], any()) -> any().
conf_get_value([H|_T]=Variable, ConfigProplist, Default) when is_list(H) ->
proplists:get_value(Variable, ConfigProplist, Default);
conf_get_value(Variable, ConfigProplist, Default) ->
conf_get_value(tokenize_variable_key(Variable), ConfigProplist, Default).


%% @doc replace the element in a proplist
-spec replace_proplist_value(atom() | string(), any(), [{string(), any()}]) -> [{string(), any()}].
Expand Down