Add helper function for adding command to Commands
This commit is contained in:
parent
b62afb32e6
commit
ea53af739a
2 changed files with 43 additions and 28 deletions
|
|
@ -44,35 +44,43 @@ async fn add(args: AddArgs, msg: &Message, ctx: &Context) -> euphoxide::Result<P
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let (event_tx, mut event_rx) = mpsc::channel(10);
|
let (event_tx, mut event_rx) = mpsc::channel(10);
|
||||||
|
|
||||||
let commands = Commands::new()
|
let mut commands = Commands::new();
|
||||||
.then(Ping::default().general("ping").hidden())
|
|
||||||
.then(Ping::default().specific("ping").hidden())
|
|
||||||
.then(
|
|
||||||
ShortHelp::new("/me demonstrates how to use euphoxide")
|
|
||||||
.general("help")
|
|
||||||
.hidden(),
|
|
||||||
)
|
|
||||||
.then(
|
|
||||||
FullHelp::new()
|
|
||||||
.with_after("Created using euphoxide.")
|
|
||||||
.specific("help")
|
|
||||||
.hidden(),
|
|
||||||
)
|
|
||||||
.then(
|
|
||||||
FromHandler::new(pyramid)
|
|
||||||
.described()
|
|
||||||
.with_description("build a pyramid")
|
|
||||||
.general("pyramid"),
|
|
||||||
)
|
|
||||||
.then(
|
|
||||||
FromClapHandler::new(add)
|
|
||||||
.clap()
|
|
||||||
.described()
|
|
||||||
.with_description("add two numbers")
|
|
||||||
.general("add"),
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
|
Ping::default()
|
||||||
|
.general("ping")
|
||||||
|
.hidden()
|
||||||
|
.add_to(&mut commands);
|
||||||
|
|
||||||
|
Ping::default()
|
||||||
|
.specific("ping")
|
||||||
|
.hidden()
|
||||||
|
.add_to(&mut commands);
|
||||||
|
|
||||||
|
ShortHelp::new("/me demonstrates how to use euphoxide")
|
||||||
|
.general("help")
|
||||||
|
.hidden()
|
||||||
|
.add_to(&mut commands);
|
||||||
|
|
||||||
|
FullHelp::new()
|
||||||
|
.with_after("Created using euphoxide.")
|
||||||
|
.specific("help")
|
||||||
|
.hidden()
|
||||||
|
.add_to(&mut commands);
|
||||||
|
|
||||||
|
FromHandler::new(pyramid)
|
||||||
|
.described()
|
||||||
|
.with_description("build a pyramid")
|
||||||
|
.general("pyramid")
|
||||||
|
.add_to(&mut commands);
|
||||||
|
|
||||||
|
FromClapHandler::new(add)
|
||||||
|
.clap()
|
||||||
|
.described()
|
||||||
|
.with_description("add two numbers")
|
||||||
|
.general("add")
|
||||||
|
.add_to(&mut commands);
|
||||||
|
|
||||||
|
let commands = commands.build();
|
||||||
let clients = MultiClient::new(event_tx);
|
let clients = MultiClient::new(event_tx);
|
||||||
|
|
||||||
clients
|
clients
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,13 @@ pub trait CommandExt: Sized {
|
||||||
fn clap(self) -> clap::Clap<Self> {
|
fn clap(self) -> clap::Clap<Self> {
|
||||||
clap::Clap(self)
|
clap::Clap(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_to<E>(self, commands: &mut Commands<E>)
|
||||||
|
where
|
||||||
|
Self: Command<E> + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
commands.add(self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sadly this doesn't work: `impl<E, C: Command<E>> CommandExt for C {}`
|
// Sadly this doesn't work: `impl<E, C: Command<E>> CommandExt for C {}`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue