-
Notifications
You must be signed in to change notification settings - Fork 414
/
info_command.ex
72 lines (61 loc) · 1.72 KB
/
info_command.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
defmodule Credo.CLI.Command.Info.InfoCommand do
@moduledoc false
use Credo.CLI.Command,
short_description: "Show useful debug information",
cli_switches: Credo.CLI.Command.Suggest.SuggestCommand.cli_switches()
alias Credo.CLI.Command.Info.InfoOutput
alias Credo.CLI.Task
alias Credo.Execution
def init(exec) do
Execution.put_pipeline(exec, "info",
load_and_validate_source_files: [
{Task.LoadAndValidateSourceFiles, []}
],
prepare_analysis: [
{Task.PrepareChecksToRun, []}
],
print_info: [
{__MODULE__.PrintInfo, []}
]
)
end
@doc false
def call(%Execution{help: true} = exec, _opts), do: InfoOutput.print_help(exec)
def call(exec, _opts), do: Execution.run_pipeline(exec, __MODULE__)
defmodule PrintInfo do
def call(exec, _opts \\ []) do
InfoOutput.print(exec, info(exec))
exec
end
defp info(exec) do
%{
"system" => %{
"credo" => Credo.version(),
"elixir" => System.version(),
"erlang" => System.otp_release()
},
"config" => %{
"plugins" => plugins(exec),
"checks" => checks(exec),
"files" => files(exec)
}
}
end
defp plugins(exec) do
Enum.map(exec.plugins, fn {name, params} ->
%{"name" => name, "params" => Enum.into(params, %{})}
end)
end
defp checks(exec) do
{checks, _only_matching, _ignore_matching} = Execution.checks(exec)
Enum.map(checks, fn {name, params} ->
%{"name" => name, "params" => Enum.into(params, %{})}
end)
end
defp files(exec) do
exec
|> Execution.get_source_files()
|> Enum.map(& &1.filename)
end
end
end