Skip to content

Commit

Permalink
Merge pull request #18 from Kyorai/mk-erlang-24-compat
Browse files Browse the repository at this point in the history
Erlang 24 compatibility
  • Loading branch information
michaelklishin authored Mar 7, 2021
2 parents b516f30 + ebd9154 commit b45ff64
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
debug_info,
warn_untyped_record]}.

{deps, [getopt, {lager, "~>3.8.0"}]}.
{deps, [getopt, {lager, "~>3.9.1"}]}.

{escript_emu_args, "%%! -escript main cuttlefish_escript +S 1 +A 0\n"}.
{escript_incl_apps, [goldrush, getopt, lager, cuttlefish]}.
Expand Down
6 changes: 3 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{"1.2.0",
[{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.2">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
{<<"lager">>,{pkg,<<"lager">>,<<"3.8.1">>},0}]}.
{<<"lager">>,{pkg,<<"lager">>,<<"3.9.1">>},0}]}.
[
{pkg_hash,[
{<<"getopt">>, <<"33D9B44289FE7AD08627DDFE1D798E30B2DA0033B51DA1B3A2D64E72CD581D02">>},
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
{<<"lager">>, <<"652EDFFBBEFFDE78F12220E1C64F6F6BFB173A8738CE73AF6ED3B1723A71C5BD">>}]},
{<<"lager">>, <<"5885BC71308CD38F9D025C8ECDE4E5CCE1CE8565F80BFC6199865C845D6DBE95">>}]},
{pkg_hash_ext,[
{<<"getopt">>, <<"A0029AEA4322FB82A61F6876A6D9C66DC9878B6CB61FAA13DF3187384FD4EA26">>},
{<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>},
{<<"lager">>, <<"F8945D2CBAAB3560C2373F0808EB6262E7CFF1BD2EC550FD7DB38716180B7465">>}]}
{<<"lager">>, <<"3F59BA75A04A99E5F18BF91C89F46DCE536F83C6CB415FE26E6E75A62BEF37DC">>}]}
].
2 changes: 1 addition & 1 deletion src/cuttlefish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ invalid(Reason) ->
%% being logged.
-spec warn(iodata()) -> ok.
warn(Str) ->
lager:warning(Str, []).
_ = lager:warning(Str, []).

-ifdef(TEST).

Expand Down
4 changes: 2 additions & 2 deletions src/cuttlefish_conf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ generate_file(Mappings, Filename) ->
_ = [ begin
io:format(S, "~s~n", [lists:flatten(Line)])
end || Line <- ConfFileLines],
% add an include directive at the end that will allow
% add an include directive at the end that will allow
% other conf files in `conf.d` and have them get picked up
% in order to override settings
% example use case is a k8s configMap that is mapped as a file
Expand Down Expand Up @@ -168,7 +168,7 @@ generate_element(MappingRecord) ->
case Level of
basic -> ok;
Level ->
lager:warning("{level, ~p} has been deprecated. Use 'hidden' or '{hidden, true}'", [Level])
_ = lager:warning("{level, ~p} has been deprecated. Use 'hidden' or '{hidden, true}'", [Level])
end,

case generate_element(Hidden, Level, Default, Commented) of
Expand Down
2 changes: 1 addition & 1 deletion src/cuttlefish_error.erl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ print(FormatString, Args) ->
print({error, ErrorTerm}) ->
print(lists:flatten(xlate(ErrorTerm)));
print(String) ->
case lager:error("~s", [String]) of
case _ = lager:error("~s", [String]) of
{error, lager_not_running} ->
io:format("~s~n", [String]),
ok;
Expand Down
58 changes: 29 additions & 29 deletions src/cuttlefish_escript.erl
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ main(Args) ->
application:set_env(lager, handlers, [{lager_stderr_backend, LogLevel}]),
application:set_env(lager, crash_log, false),
lager:start(),
lager:debug("Cuttlefish set to debug level logging"),
_ = lager:debug("Cuttlefish set to debug level logging"),

lager:debug("Parsed arguments: ~p", [ParsedArgs]),
_ = lager:debug("Parsed arguments: ~p", [ParsedArgs]),

case Command of
help ->
Expand All @@ -104,7 +104,7 @@ main(Args) ->

%% This shows the effective configuration, including defaults
effective(ParsedArgs) ->
lager:debug("cuttlefish `effective`", []),
_ = lager:debug("cuttlefish `effective`", []),
EtcDir = proplists:get_value(etc_dir, ParsedArgs),

%% Should we even show this?
Expand All @@ -114,15 +114,15 @@ effective(ParsedArgs) ->
case {AppConfigExists, VMArgsExists} of
{false, false} ->
AdvancedConfigFile = proplists:get_value(advanced_conf_file, ParsedArgs, filename:join(EtcDir, "advanced.config")),
lager:debug("Will look for advanced.config at '~s'", [AdvancedConfigFile]),
_ = lager:debug("Will look for advanced.config at '~s'", [AdvancedConfigFile]),
AdvConfig = case filelib:is_file(AdvancedConfigFile) of
true ->
lager:debug("~s detected, overlaying proplists", [AdvancedConfigFile]),
_ = lager:debug("~s detected, overlaying proplists", [AdvancedConfigFile]),
case file:consult(AdvancedConfigFile) of
{ok, [AdvancedConfig]} ->
AdvancedConfig;
{error, Error} ->
lager:error("Error parsing advanced.config: ~s", [file:format_error(Error)]),
_ = lager:error("Error parsing advanced.config: ~s", [file:format_error(Error)]),
stop_deactivate()
end;
_ ->
Expand Down Expand Up @@ -162,7 +162,7 @@ describe(_ParsedArgs, []) ->
describe(ParsedArgs, [Query|_]) when is_list(Query) ->
QDef = cuttlefish_variable:tokenize(Query),

lager:debug("cuttlefish describe '~s'", [Query]),
_ = lager:debug("cuttlefish describe '~s'", [Query]),
{_, Mappings, _} = load_schema(ParsedArgs),

FindResults = fun(QueryVar) ->
Expand Down Expand Up @@ -249,20 +249,20 @@ generate(ParsedArgs) ->
%% even though cuttlefish is awesome
FilesToUse = case {AppConfigExists, VMArgsExists} of
{true, true} ->
lager:info("~s and ~s exists, disabling cuttlefish.", [ExistingAppConfigName, ExistingVMArgsName]),
lager:info("If you'd like to know more about cuttlefish, check your local library!", []),
lager:info(" or see http://github.com/Kyorai/cuttlefish", []),
_ = lager:info("~s and ~s exists, disabling cuttlefish.", [ExistingAppConfigName, ExistingVMArgsName]),
_ = lager:info("If you'd like to know more about cuttlefish, check your local library!", []),
_ = lager:info(" or see http://github.com/Kyorai/cuttlefish", []),
{ExistingAppConfigName, ExistingVMArgsName};
{true, false} ->
lager:info("~s exists, generating vm.args", [ExistingAppConfigName]),
_ = lager:info("~s exists, generating vm.args", [ExistingAppConfigName]),
{_, NewVMArgs} = engage_cuttlefish(ParsedArgs),
{ExistingAppConfigName, NewVMArgs};
{false, true} ->
lager:info("~s exists, generating app.config", [ExistingVMArgsName]),
_ = lager:info("~s exists, generating app.config", [ExistingVMArgsName]),
{NewAppConfig, _} = engage_cuttlefish(ParsedArgs),
{NewAppConfig, ExistingVMArgsName};
_ ->
lager:info("No app.config or vm.args detected in ~s, activating cuttlefish", [EtcDir]),
_ = lager:info("No app.config or vm.args detected in ~s, activating cuttlefish", [EtcDir]),
engage_cuttlefish(ParsedArgs)
end,

Expand Down Expand Up @@ -297,10 +297,10 @@ load_schema(ParsedArgs) ->
SortedSchemaFiles = lists:sort(fun(A,B) -> A < B end, SchemaFiles),
case length(SortedSchemaFiles) of
0 ->
lager:debug("No Schema files found in specified", []),
_ = lager:debug("No Schema files found in specified", []),
stop_deactivate();
_ ->
lager:debug("SchemaFiles: ~p", [SortedSchemaFiles])
_ = lager:debug("SchemaFiles: ~p", [SortedSchemaFiles])
end,

Schema = cuttlefish_schema:files(SortedSchemaFiles),
Expand All @@ -314,10 +314,10 @@ load_schema(ParsedArgs) ->

load_conf(ParsedArgs) ->
ConfFiles = proplists:get_all_values(conf_file, ParsedArgs),
lager:debug("ConfFiles: ~p", [ConfFiles]),
_ = lager:debug("ConfFiles: ~p", [ConfFiles]),
case cuttlefish_conf:files(ConfFiles) of
{errorlist, Errors} ->
_ = [ lager:error(cuttlefish_error:xlate(E)) ||
_ = [ _ = lager:error(cuttlefish_error:xlate(E)) ||
{error, E} <- Errors],
stop_deactivate(),
{errorlist, Errors};
Expand All @@ -340,7 +340,7 @@ writable_destination_path(ParsedArgs) ->
ok ->
AbsoluteDestPath;
{error, E} ->
lager:error(
_ = lager:error(
"Error creating ~s: ~s",
[AbsoluteDestPath, file:format_error(E)]),
error
Expand All @@ -363,32 +363,32 @@ engage_cuttlefish(ParsedArgs) ->
DestinationVMArgsFilename = filename_maker(proplists:get_value(dest_file, ParsedArgs, "vm"), "args"),
DestinationVMArgs = filename:join(AbsPath, DestinationVMArgsFilename),

lager:debug("Generating config in: ~p", [Destination]),
lager:debug("Generating vm.args in: ~p", [DestinationVMArgs]),
_ = lager:debug("Generating config in: ~p", [Destination]),
_ = lager:debug("Generating vm.args in: ~p", [DestinationVMArgs]),

Schema = load_schema(ParsedArgs),
Conf = load_conf(ParsedArgs),
NewConfig = case cuttlefish_generator:map(Schema, Conf, ParsedArgs) of
{error, Phase, {errorlist, Errors}} ->
lager:error("Error generating configuration in phase ~s", [Phase]),
_ = lager:error("Error generating configuration in phase ~s", [Phase]),
_ = [ cuttlefish_error:print(E) || E <- Errors],
stop_deactivate();
ValidConfig -> ValidConfig
end,

AdvancedConfigFile = proplists:get_value(advanced_conf_file, ParsedArgs, filename:join(EtcDir, "advanced.config")),
lager:debug("AdvancedConfigFile: ~p", [AdvancedConfigFile]),
_ = lager:debug("AdvancedConfigFile: ~p", [AdvancedConfigFile]),
FinalConfig = case filelib:is_file(AdvancedConfigFile) of
true ->
lager:info("advanced config file is detected at ~s, overlaying proplists", [AdvancedConfigFile]),
_ = lager:info("advanced config file is detected at ~s, overlaying proplists", [AdvancedConfigFile]),
case file:consult(AdvancedConfigFile) of
{ok, [AdvancedConfig]} ->
cuttlefish_advanced:overlay(NewConfig, AdvancedConfig);
{ok, OtherTerms} ->
lager:error("Error parsing ~s, incorrect format: ~p", [AdvancedConfigFile, OtherTerms]),
_ = lager:error("Error parsing ~s, incorrect format: ~p", [AdvancedConfigFile, OtherTerms]),
stop_deactivate();
{error, Error} ->
lager:error("Error parsing ~s: ~s", [AdvancedConfigFile, file:format_error(Error)]),
_ = lager:error("Error parsing ~s: ~s", [AdvancedConfigFile, file:format_error(Error)]),
stop_deactivate()
end;
_ ->
Expand Down Expand Up @@ -450,7 +450,7 @@ delete([File|Files], MaxHistory) ->
case file:delete(File) of
ok -> ok;
{error, Reason} ->
lager:error("Could not delete ~s, ~p", [File, Reason])
_ = lager:error("Could not delete ~s, ~p", [File, Reason])
end,
delete(Files, MaxHistory).

Expand All @@ -464,14 +464,14 @@ delete([File|Files], MaxHistory) ->
maybe_log_file_error(_, ok) ->
ok;
maybe_log_file_error(Filename, {error, Reason}) ->
lager:error("Error writing ~s: ~s", [Filename, file:format_error(Reason)]),
_ = lager:error("Error writing ~s: ~s", [Filename, file:format_error(Reason)]),
ok.

-spec check_existence(string(), string()) -> {boolean(), string()}.
check_existence(EtcDir, Filename) ->
FullName = filename:join(EtcDir, Filename), %% Barfolomew
Exists = filelib:is_file(FullName),
lager:info("Checking ~s exists... ~p", [FullName, Exists]),
_ = lager:info("Checking ~s exists... ~p", [FullName, Exists]),
{Exists, FullName}.

filename_maker(Filename, Extension) ->
Expand Down Expand Up @@ -503,7 +503,7 @@ zero_pad(Integer) ->
end.

print_schema(Schema) ->
lager:info("Printing Schema Mappings"),
_ = lager:info("Printing Schema Mappings"),
{_, Mappings, _} = Schema,

{Max, ListOfMappings} = lists:foldr(
Expand Down
26 changes: 13 additions & 13 deletions src/cuttlefish_generator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ restrict_mappings(M, {Mappings, Keys}, ConfigKeys) ->
map_add_defaults({_, Mappings, _} = Schema, Config, ParsedArgs) ->
%% Config at this point is just what's in the .conf file.
%% add_defaults/2 rolls the default values in from the schema
lager:debug("Adding Defaults"),
_ = lager:debug("Adding Defaults"),
DConfig = add_defaults(Config, Mappings),
case cuttlefish_error:errorlist_maybe(DConfig) of
{errorlist, EList} ->
Expand All @@ -87,7 +87,7 @@ map_add_defaults({_, Mappings, _} = Schema, Config, ParsedArgs) ->
[proplists:property()] |
{error, atom(), cuttlefish_error:errorlist()}.
map_value_sub(Schema, Config, ParsedArgs) ->
lager:debug("Right Hand Side Substitutions"),
_ = lager:debug("Right Hand Side Substitutions"),
case value_sub(Config) of
{SubbedConfig, []} ->
map_transform_datatypes(Schema, SubbedConfig, ParsedArgs);
Expand All @@ -102,7 +102,7 @@ map_transform_datatypes({_, Mappings, _} = Schema, DConfig, ParsedArgs) ->
%% Everything in DConfig is of datatype "string",
%% transform_datatypes turns them into other erlang terms
%% based on the schema
lager:debug("Applying Datatypes"),
_ = lager:debug("Applying Datatypes"),
case transform_datatypes(DConfig, Mappings, ParsedArgs) of
{NewConf, []} ->
map_validate(Schema, NewConf);
Expand All @@ -115,7 +115,7 @@ map_transform_datatypes({_, Mappings, _} = Schema, DConfig, ParsedArgs) ->
{error, atom(), cuttlefish_error:errorlist()}.
map_validate(Schema, Conf) ->
%% Any more advanced validators
lager:debug("Validation"),
_ = lager:debug("Validation"),
case cuttlefish_error:errorlist_maybe(run_validations(Schema, Conf)) of
{errorlist, EList} ->
{error, validation, {errorlist, EList}};
Expand Down Expand Up @@ -160,7 +160,7 @@ apply_mappings({Translations, Mappings, _Validators}, Conf) ->
end,
{[], {ordsets:new(),ordsets:new()}},
Mappings),
lager:debug("Applied 1:1 Mappings"),
_ = lager:debug("Applied 1:1 Mappings"),

TranslationsToDrop = TranslationsToMaybeDrop -- TranslationsToKeep,
{DirectMappings, TranslationsToDrop}.
Expand All @@ -176,7 +176,7 @@ apply_translations({Translations, _, _} = Schema, Conf, DirectMappings, Translat
{DirectMappings, []}, Translations),
case Errorlist of
[] ->
lager:debug("Applied Translations"),
_ = lager:debug("Applied Translations"),
Proplist;
Es ->
{error, apply_translations, {errorlist, Es}}
Expand All @@ -191,7 +191,7 @@ fold_apply_translation(Conf, Schema, TranslationsToDrop) ->
false ->
{XlatFun, XlatArgs} = prepare_translation_fun(Conf, Schema,
Mapping, Xlat),
lager:debug("Running translation for ~s", [Mapping]),
_ = lager:debug("Running translation for ~s", [Mapping]),
case try_apply_translation(Mapping, XlatFun, XlatArgs) of
unset ->
{Acc, Errors};
Expand All @@ -201,7 +201,7 @@ fold_apply_translation(Conf, Schema, TranslationsToDrop) ->
{Acc, [{error, Term}|Errors]}
end;
_ ->
lager:debug("~p in Translations to drop...", [Mapping]),
_ = lager:debug("~p in Translations to drop...", [Mapping]),
{Acc, Errors}
end
end.
Expand Down Expand Up @@ -300,7 +300,7 @@ add_default(Conf, Prefixes, MappingRecord, Acc) ->
%% If Match =:= true, do nothing, the value is set in the .conf file
_ ->
%% TODO: Handle with more style and grace
lager:error("Both fuzzy and strict match! should not happen"),
_ = lager:error("Both fuzzy and strict match! should not happen"),
[{error, {map_multiple_match, VariableDef}}|Acc]
end.

Expand Down Expand Up @@ -415,15 +415,15 @@ transform_datatypes(Conf, Mappings, ParsedArgs) ->
%% It will prevent anything from starting, and will let you know
%% that you're trying to set something that has no effect
VarName = cuttlefish_variable:format(Variable),
lager:error("You've tried to set ~s, but there is no setting with that name.", [VarName]),
lager:error(" Did you mean one of these?"),
_ = lager:error("You've tried to set ~s, but there is no setting with that name.", [VarName]),
_ = lager:error(" Did you mean one of these?"),

Possibilities = [ begin
MapVarName = cuttlefish_variable:format(cuttlefish_mapping:variable(M)),
{cuttlefish_util:levenshtein(VarName, MapVarName), MapVarName}
end || M <- Mappings],
Sorted = lists:sort(Possibilities),
_ = [ lager:error(" ~s", [T]) || {_, T} <- lists:sublist(Sorted, 3) ],
_ = [ _ = lager:error(" ~s", [T]) || {_, T} <- lists:sublist(Sorted, 3) ],
{Acc, [ {error, {unknown_variable, VarName}} | ErrorAcc ]};
MappingRecord ->
DTs = cuttlefish_mapping:datatype(MappingRecord),
Expand Down Expand Up @@ -622,7 +622,7 @@ run_validations({_, Mappings, Validators}, Conf) ->
cuttlefish_mapping:variable(M)),
cuttlefish_validator:description(V)
}},
lager:error(cuttlefish_error:xlate(Error)),
_ = lager:error(cuttlefish_error:xlate(Error)),
{error, Error}
end
end || V <- Vs]
Expand Down
2 changes: 1 addition & 1 deletion src/cuttlefish_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ string(S, {T, M, V}) ->
{error, {Line, erl_scan, _}, _} ->
Error = {erl_scan, Line},
ErrStr = cuttlefish_error:xlate(Error),
lager:error(lists:flatten(ErrStr)),
_ = lager:error(lists:flatten(ErrStr)),
{errorlist, [{error, Error}]}
end.

Expand Down
2 changes: 1 addition & 1 deletion src/cuttlefish_unit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ multiple_schema_generate_templated_config_test() ->
], []},

Config = cuttlefish_unit:generate_templated_config("test/sample_mustache.schema", [], Context, PrereqSchema),
lager:error("~p", [Config]),
_ = lager:error("~p", [Config]),
assert_config(Config, "app_a.setting_b", "/c/mustache/a.b"),
ok.

Expand Down
Loading

0 comments on commit b45ff64

Please sign in to comment.