Current section
Files
Jump to
Current section
Files
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_dev_dependencies/2, filter_advisory_ids/2, filter_severity/2, parse_config_format/1, read_config/1, merge_flags_and_config/2, spin_up/2]).
-export_type([format/0, config/0, flags/0]).
-type format() :: minimal | detailed | json.
-type config() :: {config,
list(binary()),
boolean(),
boolean(),
boolean(),
boolean(),
format(),
boolean(),
list(binary()),
list(binary()),
list(binary()),
boolean()}.
-type flags() :: {flags,
boolean(),
boolean(),
boolean(),
boolean(),
boolean(),
gleam@option:option(format())}.
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 127).
-spec filter_packages(config(), list(go_over@packages:package())) -> list(go_over@packages:package()).
filter_packages(Conf, Pkgs) ->
gxyz@gxyz_list:reject(
Pkgs,
fun(Pkg) ->
gleam@list:contains(erlang:element(9, Conf), erlang:element(2, Pkg))
end
).
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 133).
-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.
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 140).
-spec filter_dev_dependencies(config(), list(go_over@packages:package())) -> list(go_over@packages:package()).
filter_dev_dependencies(Conf, Pkgs) ->
case erlang:element(12, Conf) of
false ->
Pkgs;
true ->
gxyz@gxyz_list:reject(
Pkgs,
fun(Pkg) ->
gleam@list:contains(
erlang:element(2, Conf),
erlang:element(2, Pkg)
)
end
)
end.
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 151).
-spec filter_advisory_ids(
config(),
list(go_over@advisories@advisories:advisory())
) -> list(go_over@advisories@advisories:advisory()).
filter_advisory_ids(Conf, Advisories) ->
gxyz@gxyz_list:reject(
Advisories,
fun(Adv) ->
gleam@list:contains(
erlang:element(11, Conf),
erlang:element(2, Adv)
)
end
).
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 160).
-spec filter_severity(config(), list(go_over@warning:warning())) -> list(go_over@warning:warning()).
filter_severity(Conf, Warnings) ->
gxyz@gxyz_list:reject(
Warnings,
fun(W) ->
gleam@list:contains(
erlang:element(10, Conf),
string:lowercase(erlang:element(7, W))
)
end
).
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 166).
-spec parse_config_format(binary()) -> gleam@option:option(format()).
parse_config_format(Val) ->
case string:lowercase(Val) of
<<"json"/utf8>> ->
{some, json};
<<"detailed"/utf8>> ->
{some, detailed};
<<"minimal"/utf8>> ->
{some, minimal};
Format ->
go_over@util@print:warning(
<<<<"Invalid format '"/utf8, Format/binary>>/binary,
"' valid options are ['json', 'detailed', 'minimal'], defaulting to minimal"/utf8>>
),
none
end.
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 182).
-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),
erlang:error(#{gleam_error => panic,
message => <<"Unreachable, please create an issue in https://github.com/bwireman/go-over if you see this"/utf8>>,
module => <<"go_over/config"/utf8>>,
function => <<"toml_as_string"/utf8>>,
line => 188})
end.
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 54).
-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,
Dev_deps = begin
_pipe@2 = tom:get_table(Gleam, [<<"dev-dependencies"/utf8>>]),
_pipe@3 = gleam@result:unwrap(_pipe@2, maps:new()),
maps:keys(_pipe@3)
end,
Go_over = begin
_pipe@4 = tom:get_table(Gleam, [<<"go-over"/utf8>>]),
gleam@result:unwrap(_pipe@4, maps:new())
end,
Ignore = begin
_pipe@5 = tom:get_table(Go_over, [<<"ignore"/utf8>>]),
gleam@result:unwrap(_pipe@5, maps:new())
end,
Cache = begin
_pipe@6 = tom:get_bool(Go_over, [<<"cache"/utf8>>]),
gleam@result:unwrap(_pipe@6, true)
end,
Outdated = begin
_pipe@7 = tom:get_bool(Go_over, [<<"outdated"/utf8>>]),
gleam@result:unwrap(_pipe@7, false)
end,
Format = begin
_pipe@8 = tom:get_string(Go_over, [<<"format"/utf8>>]),
_pipe@9 = gleam@result:unwrap(_pipe@8, <<"minimal"/utf8>>),
string:lowercase(_pipe@9)
end,
Ignore_indirect = begin
_pipe@10 = tom:get_bool(Ignore, [<<"indirect"/utf8>>]),
gleam@result:lazy_unwrap(
_pipe@10,
fun() -> case tom:get_bool(Go_over, [<<"ignore_indirect"/utf8>>]) of
{ok, Value} ->
go_over@util@print:high(
<<"Warning: `go-over.ignore_indirect` is deprecated, use `go-over.ignore.indirect` instead"/utf8>>
),
Value;
{error, _} ->
false
end end
)
end,
Packages = begin
_pipe@11 = tom:get_array(Ignore, [<<"packages"/utf8>>]),
gleam@result:unwrap(_pipe@11, [])
end,
Severity = begin
_pipe@12 = tom:get_array(Ignore, [<<"severity"/utf8>>]),
gleam@result:unwrap(_pipe@12, [])
end,
Ids = begin
_pipe@13 = tom:get_array(Ignore, [<<"ids"/utf8>>]),
gleam@result:unwrap(_pipe@13, [])
end,
Ignore_dev_dependencies = begin
_pipe@14 = tom:get_bool(Ignore, [<<"dev_dependencies"/utf8>>]),
gleam@result:unwrap(_pipe@14, false)
end,
{config,
Dev_deps,
Outdated,
Ignore_indirect,
not Cache,
false,
begin
_pipe@15 = parse_config_format(Format),
gleam@option:unwrap(_pipe@15, minimal)
end,
false,
begin
_pipe@16 = gleam@list:map(Packages, fun toml_as_string/1),
gleam@option:values(_pipe@16)
end,
begin
_pipe@17 = gleam@list:map(Severity, fun toml_as_string/1),
gleam@option:values(_pipe@17)
end,
begin
_pipe@18 = gleam@list:map(Ids, fun toml_as_string/1),
gleam@option:values(_pipe@18)
end,
Ignore_dev_dependencies}.
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 194).
-spec help_message(clip@arg_info:arg_info()) -> binary().
help_message(Args) ->
_pipe = {arg_info,
erlang:element(2, Args),
erlang:element(3, Args),
gxyz@gxyz_list:reject(
erlang:element(4, Args),
fun(F) -> erlang:element(2, F) =:= <<"fake"/utf8>> end
),
erlang:element(5, Args)},
_pipe@2 = clip@arg_info:help_text(
_pipe,
<<"go_over"/utf8>>,
<<(begin
_pipe@1 = <<" ____ ____ ____ _ _____ _____
/ __ `/ __ \\ / __ \\ | / / _ \\/ ___/
/ /_/ / /_/ / / /_/ / |/ / __/ /
\\__, /\\____/____\\____/|___/\\___/_/
/____/ /_____/
"/utf8>>,
go_over@util@print:format_high(_pipe@1)
end)/binary,
"🕵️♂️ Audit Erlang & Elixir dependencies, to make sure your gleam projects really ✨ sparkle!"/utf8>>
),
gleam_stdlib:crop_string(_pipe@2, <<" "/utf8>>).
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 216).
-spec merge_flags_and_config(flags(), config()) -> config().
merge_flags_and_config(Flags, Cfg) ->
{config,
erlang:element(2, Cfg),
erlang:element(3, Cfg) orelse erlang:element(4, Flags),
erlang:element(4, Cfg) orelse erlang:element(5, Flags),
erlang:element(2, Flags) orelse erlang:element(5, Cfg),
erlang:element(3, Flags),
gleam@option:unwrap(erlang:element(7, Flags), erlang:element(7, Cfg)),
erlang:element(6, Flags),
erlang:element(9, Cfg),
erlang:element(10, Cfg),
erlang:element(11, Cfg),
erlang:element(12, Cfg)}.
-file("/home/bwireman/src/go-over/src/go_over/config.gleam", 232).
-spec spin_up(config(), list(binary())) -> {ok, config()} | {error, binary()}.
spin_up(Cfg, Argv) ->
_pipe = clip:command(
begin
clip:parameter(
fun(Force) ->
clip:parameter(
fun(Outdated) ->
clip:parameter(
fun(Ignore_indirect) ->
clip:parameter(
fun(Fake) ->
clip:parameter(
fun(Verbose) ->
clip:parameter(
fun(Format) ->
merge_flags_and_config(
{flags,
Force,
Fake,
Outdated,
Ignore_indirect,
Verbose,
Format},
Cfg
)
end
)
end
)
end
)
end
)
end
)
end
)
end
),
_pipe@1 = clip:flag(
_pipe,
clip@flag:help(
clip@flag:new(<<"force"/utf8>>),
<<"Force pulling new data even if the cached data is still valid"/utf8>>
)
),
_pipe@2 = clip:flag(
_pipe@1,
clip@flag:help(
clip@flag:new(<<"outdated"/utf8>>),
<<"Additionally check if newer versions of dependencies exist"/utf8>>
)
),
_pipe@3 = clip:flag(
_pipe@2,
clip@flag:help(
clip@flag:new(<<"ignore-indirect"/utf8>>),
<<"Ignore all warnings for indirect dependencies"/utf8>>
)
),
_pipe@4 = clip:flag(_pipe@3, clip@flag:new(<<"fake"/utf8>>)),
_pipe@5 = clip:flag(
_pipe@4,
clip@flag:help(
clip@flag:new(<<"verbose"/utf8>>),
<<"Print progress as packages are checked"/utf8>>
)
),
_pipe@9 = clip:opt(
_pipe@5,
begin
_pipe@6 = clip@opt:new(<<"format"/utf8>>),
_pipe@7 = clip@opt:help(
_pipe@6,
<<"Specify the output format of any warnings, [minimal, verbose, json]"/utf8>>
),
_pipe@8 = clip@opt:map(_pipe@7, fun parse_config_format/1),
clip@opt:default(_pipe@8, none)
end
),
_pipe@10 = clip:help(_pipe@9, clip@help:custom(fun help_message/1)),
clip:run(
_pipe@10,
begin
_pipe@11 = Argv,
_pipe@12 = gxyz@gxyz_list:reject(
_pipe@11,
fun(_capture) ->
gleam_stdlib:string_ends_with(_capture, <<".js"/utf8>>)
end
),
_pipe@13 = gxyz@gxyz_list:reject(
_pipe@12,
fun(_capture@1) ->
gleam_stdlib:string_ends_with(_capture@1, <<".mjs"/utf8>>)
end
),
gxyz@gxyz_list:reject(
_pipe@13,
fun(_capture@2) ->
gleam_stdlib:string_ends_with(_capture@2, <<".cjs"/utf8>>)
end
)
end
).