validate_options.ex (1089B)
1 defmodule Credo.Execution.Task.ValidateOptions do 2 @moduledoc false 3 4 use Credo.Execution.Task 5 6 alias Credo.CLI.Options 7 alias Credo.CLI.Output.UI 8 9 @exit_status Credo.CLI.ExitStatus.config_loaded_but_invalid() 10 11 def call(exec, _opts) do 12 case exec.cli_options do 13 %Options{unknown_args: [], unknown_switches: []} -> 14 exec 15 16 _ -> 17 Execution.halt(exec) 18 end 19 end 20 21 @spec error(Credo.Execution.t(), keyword()) :: no_return 22 def error(exec, _opts) do 23 UI.use_colors(exec) 24 25 Enum.each(exec.cli_options.unknown_args, &print_argument(exec, &1)) 26 Enum.each(exec.cli_options.unknown_switches, &print_switch(exec, &1)) 27 28 put_exit_status(exec, @exit_status) 29 end 30 31 defp print_argument(exec, name) do 32 UI.warn([ 33 :red, 34 "** (credo) Unknown argument for `#{exec.cli_options.command}` command: #{name}" 35 ]) 36 end 37 38 defp print_switch(exec, {name, _value}), do: print_switch(exec, name) 39 40 defp print_switch(exec, name) do 41 UI.warn([:red, "** (credo) Unknown switch for `#{exec.cli_options.command}` command: #{name}"]) 42 end 43 end