artificery v0.4.2 Artificery.Console

A minimal logger

Link to this section Summary

Functions

Ask the user to provide data in response to a question

Updates the logger configuration with the given options.

Prints a debug message, only visible when verbose mode is on

Prints an error message, and then halts the process

Terminates the process with the given status code

Prints an info message

Provides a spinner while some long-running work is being done.

Prints a success message

Updates a running spinner with the provided status text

Prints a warning message

Write text or iodata to standard output.

Ask the user a question which requires a yes/no answer, returns a boolean

Link to this section Functions

Link to this function

ask(question, opts \\ [])

Ask the user to provide data in response to a question

The value returned is dependent on whether a transformation is applied, and whether blank answers are accepted. By default, empty strings will return nil if no alternate default is supplied and either no validator was supplied, or it returned :ok for blank answers.

If you supply a default, instead of nil, the default will be returned. Again this only applies if a blank answer is considered valid.

You may validate answers by supplying a function (bound or captured) via the validator: fun option. This function will receive the raw input string supplied by the user, and should return :ok if the answer is valid, or {:error, validation_error}, where validation_error is a string which will be displayed to the user before asking them to answer the question again.

You may apply a transformation to answers, so that rather than getting a string back, you get the value in a state useful for your application. You may provide a transform via the transform: fun option, and this will receive the raw input string the user provided after the validator has validated the input, if one was supplied, and if the user input was non-nil.

Supply default values with the default: term option

Link to this function

configure(opts)
configure(Keyword.t()) :: Keyword.t()

Updates the logger configuration with the given options.

Link to this function

debug(device \\ :stdio, msg)
debug(:standard_error | :stdio, String.t()) :: :ok

Prints a debug message, only visible when verbose mode is on

Link to this function

error(device \\ :stdio, msg)
error(:standard_error | :stdio, String.t()) :: no_return()

Prints an error message, and then halts the process

Terminates the process with the given status code

Link to this function

info(device \\ :stdio, msg)
info(:standard_error | :stdio, String.t()) :: :ok

Prints an info message

Link to this function

notice(device \\ :stdio, msg)
notice(:standard_error | :stdio, String.t()) :: :ok

Prints a notice

Link to this macro

spinner(msg, opts \\ [], list) (macro)

Provides a spinner while some long-running work is being done.

Options

  • spinner: one of the spinners defined in Artificery.Console.Spinner

Example

Console.spinner "Loading...", [spinner: :simple_dots] do
  :timer.sleep(5_000)
end
Link to this function

success(device \\ :stdio, msg)
success(:standard_error | :stdio, String.t()) :: :ok

Prints a success message

Link to this function

update_spinner(status)
update_spinner(String.t()) :: :ok

Updates a running spinner with the provided status text

Link to this function

warn(device \\ :stdio, msg)
warn(:standard_error | :stdio, String.t()) :: :ok

Prints a warning message

Link to this function

write(msg)
write(iodata()) :: :ok

Write text or iodata to standard output.

You may optionally pass a list of styles to apply to the output, as well as the device to write to (:standard_error, or :stdio)

Link to this function

write(msg, styles)
write(iodata(), [atom()]) :: :ok

Link to this function

write(device, msg, styles)
write(:standard_error | :stdio, iodata(), [atom()]) :: :ok

Ask the user a question which requires a yes/no answer, returns a boolean