Closed sadorowo closed 1 year ago
bug discovered; you can pass some subcommand to default_subcommand
even if subcommands
does not contain this value
EDIT: added a review
Thank you for taking the time to contribute a feature!
I wonder if the additional API surface and maintenance is worth it... Especially because text commands are used less and less
You can already do this:
#[poise::command(prefix_command, slash_command, subcommands("show", "edit"))]
pub async fn configuration(ctx: Context<'_>) -> Result<(), Error> {
show_impl().await;
}
async fn show_impl(ctx: Context<'_>) -> Result<(), Error> {
// ...
}
#[poise::command(prefix_command, slash_command)]
pub async fn show(ctx: Context<'_>) -> Result<(), Error> {
show_impl().await
}
#[poise::command(prefix_command, slash_command)]
pub async fn edit(ctx: Context<'_>) -> Result<(), Error> {
// ...
}
Thank you for taking the time to contribute a feature!
I wonder if the additional API surface and maintenance is worth it... Especially because text commands are used less and less
You can already do this:
#[poise::command(prefix_command, slash_command, subcommands("show", "edit"))] pub async fn configuration(ctx: Context<'_>) -> Result<(), Error> { show_impl().await; } async fn show_impl(ctx: Context<'_>) -> Result<(), Error> { // ... } #[poise::command(prefix_command, slash_command)] pub async fn show(ctx: Context<'_>) -> Result<(), Error> { show_impl().await } #[poise::command(prefix_command, slash_command)] pub async fn edit(ctx: Context<'_>) -> Result<(), Error> { // ... }
that's true, prefix commands are going to be deprecated in favor of slash commands, I will leave it up to you to decide whether to accept/reject this PR
I created sth better I think.
Hello, I have enhanced the library with an interesting function. Let's create an example of a command with subcommands.
But I created a simple parameter in poise::command proc macro. From now, you can use
default_subcommand
parameter. No more repeating code!default_subcommand
sets the default subcommand; when no subcommand is given, the default subcommand will be runExample:
I think this would be a great feature, you won't have to repeat your code. I've tested a few cases and everything works fine, although I would recommend checking my code more thoroughly for possible errors/shortcomings before accepting the PR.
Errors that I have implemented:
Feel free to edit my code, it may be not perfect.