View Source Credo.CLI.Command behaviour (Credo v1.7.5)

Command is used to describe commands which can be executed from the command line.

The default command is Credo.CLI.Command.Suggest.SuggestCommand.

A basic command that writes "Hello World" can be implemented like this:

defmodule HelloWorldCommand do
  use Credo.CLI.Command

  alias Credo.CLI.Output.UI

  def call(_exec, _opts) do
    UI.puts([:yellow, "Hello ", :orange, "World"])
  end
end

Summary

Callbacks

Is called when a Command is invoked.

Runs the Command

Is called when a Command is initialized.

Returns a short, one-line description of what the command does

Callbacks

@callback call(exec :: Credo.Execution.t()) :: Credo.Execution.t()

Is called when a Command is invoked.

defmodule FooTask do
  use Credo.Execution.Task

  def call(exec) do
    IO.inspect(exec)
  end
end

The call/1 functions receives an exec struct and must return a (modified) Credo.Execution.

@callback call(exec :: Credo.Execution.t(), opts :: list()) :: Credo.Execution.t()

Runs the Command

@callback cli_switches() :: [Map.t()]
@callback init(exec :: Credo.Execution.t()) :: Credo.Execution.t()

Is called when a Command is initialized.

The init/1 functions receives an exec struct and must return a (modified) Credo.Execution.

This can be used to initialize Execution pipelines for the current Command:

defmodule FooTask do
  use Credo.Execution.Task

  def init(exec) do
    Execution.put_pipeline(exec, __MODULE__,
      run_my_thing: [
        {RunMySpecialThing, []}
      ],
      filter_results: [
        {FilterResults, []}
      ],
      print_results: [
        {PrintResultsAndSummary, []}
      ]
    )
  end
end
@callback short_description() :: String.t()

Returns a short, one-line description of what the command does

Link to this callback

treat_unknown_args_as_files?()

View Source
@callback treat_unknown_args_as_files?() :: boolean()