Credo.CLI.Command behaviour (Credo v1.6.0) View Source
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
Link to this section 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
Link to this section Callbacks
Specs
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
.
Specs
call(exec :: Credo.Execution.t(), opts :: list()) :: Credo.Execution.t()
Runs the Command
Specs
cli_switches() :: [Map.t()]
Specs
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
Specs
short_description() :: String.t()
Returns a short, one-line description of what the command does