JumarCli.Command behaviour (Jumar v0.1.0)

View Source

A module for CLI commands and subcommands that can be executed by the Jumar CLI. This follows a very similar pattern to Mix.Task in Elixir, but is used for the released application CLI in Jumar Docker.

Summary

Types

A list of command line arguments passed to the command.

Any module that implements the JumarCli.Command behaviour.

The name of the command. This is the name used in the CLI.

Commands can return different values depending on what the command does. They can return

Callbacks

This is the command actual ran by the CLI.

Functions

Returns the command name for the given module.

Gets the moduledoc for the given command module.

Gets the shortdoc for the given command module.

Types

args()

@type args() :: [String.t()]

A list of command line arguments passed to the command.

mod()

@type mod() :: module()

Any module that implements the JumarCli.Command behaviour.

name()

@type name() :: String.t()

The name of the command. This is the name used in the CLI.

return_value()

@type return_value() :: :ok | {:ok, pid()} | {:error, :help_text} | {:error, any()}

Commands can return different values depending on what the command does. They can return:

  • :ok which will exit the CLI with a status code of 0.

  • {:ok, pid()} which monitor the pid as the main process of the CLI. This can be used for starting a web server or other long running processes.

  • {:error, :help_text} which will print the help text for the command and exit the CLI with a status code of 1.

  • {:error, any()} which will print the error message and exit the CLI with a status code of 1.

Callbacks

run(args)

@callback run(args()) :: return_value()

This is the command actual ran by the CLI.

Functions

command_name(module)

@spec command_name(mod()) :: name()

Returns the command name for the given module.

Examples

iex> JumarCli.Command.command_name(JumarCli.Commands.Migrate)
"migrate"

moduledoc(module)

@spec moduledoc(mod()) :: String.t()

Gets the moduledoc for the given command module.

shortdoc(module)

@spec shortdoc(mod()) :: String.t()

Gets the shortdoc for the given command module.