nosedrum v0.1.0 Nosedrum.Storage behaviour View Source

Storages contain commands and are used by command invokers to look up commands.

How you start a storage is up to the module itself - what is expected is that storage modules implement the behaviours documented in this module.

Link to this section Summary

Types

A single command module or mapping of subcommand names to subcommand modules

The "invocation path" of the command

Callbacks

Add a new command under the given path

Return a mapping of command names to command_group/0s

Look up a command group under the specified name

Remove the command under the given path

Link to this section Types

Link to this type

command_group() View Source
command_group() ::
  Module.t()
  | %{optional(:default) => Module.t(), required(String.t()) => Module.t()}

A single command module or mapping of subcommand names to subcommand modules.

In addition to subcommand names, the key :default can be specified by the module. :default is invoked when none of the subcommands in the map match.

Link to this type

command_path() View Source
command_path() :: {String.t()} | {String.t(), String.t() | :default}

The "invocation path" of the command.

The public-facing API of storage modules should use this in order to allow users to identify the command they want to operate on.

Usage

To identify a single command, use a single element tuple, such as {"echo"}. To identify a subcommand, use a pair, such as {"infraction", "search"}. To identify the default subcommand invoked when no matching subcommand is found, specify the group name first, then :default, such as {"tags", :default}.

Link to this section Callbacks

Link to this callback

add_command(path, command) View Source
add_command(path :: command_group(), command :: Module.t()) ::
  :ok | {:error, String.t()}

Add a new command under the given path.

If the command already exists, no error should be returned.

Link to this callback

all_commands() View Source
all_commands() :: %{optional(String.t()) => command_group()}

Return a mapping of command names to command_group/0s.

For top-level commands, the value should be a string, otherwise, a mapping of subcommand names to subcommand modules as described on command_group/0s documentation should be returned.

Link to this callback

lookup_command(name) View Source
lookup_command(name :: String.t()) :: command_group() | nil

Look up a command group under the specified name.

If the command was not found, nil should be returned.

Link to this callback

remove_command(path) View Source
remove_command(path :: command_path()) :: :ok | {:error, String.t()}

Remove the command under the given path.

If the command does not exist, no error should be returned.