Skip to content

Commit 83e9790

Browse files
committed
Add executesFailure helper method
1 parent 9c2614e commit 83e9790

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/src/commonMain/kotlin/org/anvilpowered/kbrig/builder/BuilderExtensions.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import org.anvilpowered.kbrig.SuspendingCommand
1313
import org.anvilpowered.kbrig.context.CommandContext
1414
import org.anvilpowered.kbrig.toBlocking
1515

16+
fun <S, B : ArgumentBuilder<S, B>> B.executesSuspending(command: SuspendingCommand<S>?) = executes(command?.toBlocking())
17+
1618
fun <S, B : ArgumentBuilder<S, B>> B.executesSingleSuccess(block: (context: CommandContext<S>) -> Unit) =
1719
executes { context ->
1820
try {
@@ -24,4 +26,12 @@ fun <S, B : ArgumentBuilder<S, B>> B.executesSingleSuccess(block: (context: Comm
2426
}
2527
}
2628

27-
fun <S, B : ArgumentBuilder<S, B>> B.executesSuspending(command: SuspendingCommand<S>?) = executes(command?.toBlocking())
29+
fun <S, B : ArgumentBuilder<S, B>> B.executesFailure(block: (context: CommandContext<S>) -> Unit) =
30+
executes { context ->
31+
try {
32+
block(context)
33+
} catch (e: Exception) {
34+
e.printStackTrace()
35+
}
36+
0
37+
}

0 commit comments

Comments
 (0)