Current section

Files

Jump to
go_over src go_over@config.erl
Raw

src/go_over@config.erl

-module(go_over@config).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([filter_packages/2, filter_indirect/2, filter_advisory_ids/2, filter_severity/2, parse_config_format/1, read_config/1]).
-export_type([format/0, config/0]).
-type format() :: minimal | detailed | json.
-type config() :: {config,
boolean(),
boolean(),
boolean(),
boolean(),
boolean(),
format(),
list(binary()),
list(binary()),
list(binary())}.
-spec filter_packages(config(), list(go_over@packages:package())) -> list(go_over@packages:package()).
filter_packages(Conf, Pkgs) ->
gleam@list:filter(
Pkgs,
fun(Pkg) ->
not gleam@list:contains(
erlang:element(8, Conf),
erlang:element(2, Pkg)
)
end
).
-spec filter_indirect(config(), list(go_over@packages:package())) -> list(go_over@packages:package()).
filter_indirect(Conf, Pkgs) ->
case erlang:element(4, Conf) of
false ->
Pkgs;
true ->
gleam@list:filter(Pkgs, fun(Pkg) -> erlang:element(5, Pkg) end)
end.
-spec filter_advisory_ids(
config(),
list(go_over@advisories@advisories:advisory())
) -> list(go_over@advisories@advisories:advisory()).
filter_advisory_ids(Conf, Advs) ->
gleam@list:filter(
Advs,
fun(Adv) ->
not gleam@list:contains(
erlang:element(10, Conf),
erlang:element(2, Adv)
)
end
).
-spec filter_severity(config(), list(go_over@warning:warning())) -> list(go_over@warning:warning()).
filter_severity(Conf, Warnings) ->
gleam@list:filter(
Warnings,
fun(W) ->
not gleam@list:contains(
erlang:element(9, Conf),
gleam@string:lowercase(erlang:element(7, W))
)
end
).
-spec parse_config_format(binary()) -> format().
parse_config_format(Val) ->
case Val of
<<"json"/utf8>> ->
json;
<<"detailed"/utf8>> ->
detailed;
_ ->
minimal
end.
-spec toml_as_string(tom:toml()) -> gleam@option:option(binary()).
toml_as_string(Toml) ->
case Toml of
{string, S} ->
{some, S};
_ ->
go_over@util@print:warning(
<<"could not parse config value "/utf8,
(gleam@string:inspect(Toml))/binary>>
),
shellout_ffi:os_exit(1),
none
end.
-spec read_config(binary()) -> config().
read_config(Path) ->
Res = begin
_pipe = simplifile:read(Path),
go_over@util@util:hard_fail(
_pipe,
<<"could not read config file at "/utf8, Path/binary>>
)
end,
Gleam = begin
_pipe@1 = tom:parse(Res),
go_over@util@util:hard_fail(
_pipe@1,
<<"could not read config file at "/utf8, Path/binary>>
)
end,
Go_over = begin
_pipe@2 = tom:get_table(Gleam, [<<"go-over"/utf8>>]),
gleam@result:unwrap(_pipe@2, gleam@dict:new())
end,
Cache = begin
_pipe@3 = tom:get_bool(Go_over, [<<"cache"/utf8>>]),
gleam@result:unwrap(_pipe@3, true)
end,
Outdated = begin
_pipe@4 = tom:get_bool(Go_over, [<<"outdated"/utf8>>]),
gleam@result:unwrap(_pipe@4, false)
end,
Ignore_indirect = begin
_pipe@5 = tom:get_bool(Go_over, [<<"ignore_indirect"/utf8>>]),
gleam@result:unwrap(_pipe@5, false)
end,
Format = begin
_pipe@6 = tom:get_string(Go_over, [<<"format"/utf8>>]),
_pipe@7 = gleam@result:unwrap(_pipe@6, <<"minimal"/utf8>>),
gleam@string:lowercase(_pipe@7)
end,
Ignore = begin
_pipe@8 = tom:get_table(Go_over, [<<"ignore"/utf8>>]),
gleam@result:unwrap(_pipe@8, gleam@dict:new())
end,
Packages = begin
_pipe@9 = tom:get_array(Ignore, [<<"packages"/utf8>>]),
gleam@result:unwrap(_pipe@9, [])
end,
Severity = begin
_pipe@10 = tom:get_array(Ignore, [<<"severity"/utf8>>]),
gleam@result:unwrap(_pipe@10, [])
end,
Ids = begin
_pipe@11 = tom:get_array(Ignore, [<<"ids"/utf8>>]),
gleam@result:unwrap(_pipe@11, [])
end,
{config,
Cache,
Outdated,
Ignore_indirect,
false,
false,
parse_config_format(Format),
begin
_pipe@12 = gleam@list:map(Packages, fun toml_as_string/1),
gleam@option:values(_pipe@12)
end,
begin
_pipe@13 = gleam@list:map(Severity, fun toml_as_string/1),
gleam@option:values(_pipe@13)
end,
begin
_pipe@14 = gleam@list:map(Ids, fun toml_as_string/1),
gleam@option:values(_pipe@14)
end}.