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/0
s
Look up a command group under the specified name
Remove the command under the given path
Link to this section Types
command_group() View Source
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.
command_path() View Source
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
add_command(path, command)
View Source
add_command(path :: command_group(), command :: Module.t()) ::
:ok | {:error, String.t()}
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.
all_commands()
View Source
all_commands() :: %{optional(String.t()) => command_group()}
all_commands() :: %{optional(String.t()) => command_group()}
Return a mapping of command names to command_group/0
s.
For top-level commands, the value should be a string, otherwise,
a mapping of subcommand names to subcommand modules as described
on command_group/0
s documentation should be returned.
lookup_command(name)
View Source
lookup_command(name :: String.t()) :: command_group() | nil
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.
remove_command(path)
View Source
remove_command(path :: command_path()) :: :ok | {:error, String.t()}
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.