zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

info_command.ex (1759B)


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