5 unstable releases
0.3.1 | Jun 26, 2022 |
---|---|
0.3.0 | Jun 21, 2022 |
0.2.0 | Jun 19, 2022 |
0.1.1 | Jun 19, 2022 |
0.1.0 | Jun 19, 2022 |
#16 in #dispatcher
25KB
686 lines
yogurt
Yogurt is a rust command library.
Example:
use yogurt::argument::parser::IntArgument;
use yogurt::{Command, Dispatcher};
fn main() {
// Create a dispatcher
let dispatcher = Dispatcher::builder()
// command prefix, defaults to none
.prefix("/")
// context factory, new context is created for every executed command
.context(Box::new(|| ()))
.child(
Command::literal("ping").child(
Command::argument("number", IntArgument, true).exec(Box::new(|ctx| {
println!("{:?}", ctx);
Ok(())
}))
)
)
.build()
// fails if no context factory provided
.unwrap();
// run command
dispatcher.run_command("/ping 3").unwrap();
}
lib.rs
:
yogurt
Yogurt is a rust command library.
Example:
use yogurt::argument::parser::IntArgument;
use yogurt::{Command, Dispatcher};
// Create a dispatcher
let dispatcher = Dispatcher::builder()
// command prefix, defaults to none
.prefix("/")
.base_context(())
// context factory, new context is created for every executed command
.context_factory(|_| ())
.child(
Command::literal("ping").child(
Command::argument("number", IntArgument, true).exec(|ctx| {
println!("{:?}", ctx);
Ok(())
})
)
)
.build()
// fails if no context factory provided
.unwrap();
// run command
dispatcher.run_command("/ping 3").unwrap();
Dependencies
~1MB
~19K SLoC