-
Notifications
You must be signed in to change notification settings - Fork 414
/
cli.ex
57 lines (45 loc) · 1.17 KB
/
cli.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
defmodule Credo.CLI do
@moduledoc """
`Credo.CLI` is the entrypoint for both the Mix task and the escript.
"""
alias Credo.Execution
@doc """
Runs Credo with the given `argv` and exits the process.
See `Credo.run/1` if you want to run Credo programmatically.
"""
def main(argv \\ []) do
Credo.Application.start(nil, nil)
{options, _argv_rest, _errors} = OptionParser.parse(argv, strict: [watch: :boolean])
if options[:watch] do
run_to_watch(argv)
else
run_to_halt(argv)
end
end
@doc false
@deprecated "Use Credo.run/1 instead"
def run(argv) do
Credo.run(argv)
end
defp run_to_watch(argv) do
Credo.Watcher.run(argv)
receive do
_ -> nil
end
end
defp run_to_halt(argv) do
argv
|> Credo.run()
|> halt_if_exit_status_assigned()
end
defp halt_if_exit_status_assigned(%Execution{mute_exit_status: true}) do
# Skip if exit status is muted
end
defp halt_if_exit_status_assigned(exec) do
exec
|> Execution.get_assign("credo.exit_status", 0)
|> halt_if_failed()
end
defp halt_if_failed(0), do: nil
defp halt_if_failed(exit_status), do: exit({:shutdown, exit_status})
end