Oberst
A type-safe command parser & dispatcher inspired by Brigadier and written in Rust.
Usage
Creating a command source
Oberst leverages Rust's procedural macros in order to generate a command's syntax from a set of ordinary functions. To use it, you first need a CommandSource<C>. Here, C can be any struct you want your commands to have access to:
use CommandSource;
Defining a command
Commands are defined with the define_command macro :
use
define_command!
Commands can accept whitespace-separated arguments of any type that implements Obersts' Argument trait. See the oberst::parser module for more info. While you can implement Argument for your custom types, Oberst comes with default implementation for built-in types such as integer types and String.
With the args attribute, it is possible to build a more sophisticated command syntax by allowing the command to parse both arguments and literals. However, arguments within an args attribute must appear in the same order as they do in the function's signature.
Commands have to return either () or oberst::CommandResult. The latter supports returning any error values that implement std::error::Error.
Registering a command
Commands can be registered to a source using the register_command! helper macro:
Roadmap
- Command creation & dispatchment
- Argument parsers for most std types
- Add support for both
CommandResultand()return values - Add support for custom syntax with
#[args = "..."] - Add support for multithreaded commands
- Make
CommandSourceclonable to avoid having to pass references around