diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt index 1e0a9af2a..690694d4e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt @@ -31,16 +31,18 @@ public interface CommandSignatureVariant { @ExperimentalCommandDescriptors public interface ICommandParameter { public val name: String - public val type: KType + + /** + * If [isOptional] is `false`, [defaultValue] is always `null`. + * Otherwise [defaultValue] may be `null` iff [T] is nullable. + */ public val defaultValue: T? + public val isOptional: Boolean - public companion object { - @get:JvmStatic - @ExperimentalCommandDescriptors - public val ICommandParameter<*>.isOptional: Boolean - get() = this.defaultValue != null - - } + /** + * Reified type of [T] + */ + public val type: KType } @ExperimentalCommandDescriptors @@ -54,9 +56,10 @@ public sealed class CommandValueParameter : ICommandParameter { public class StringConstant( public override val name: String, - public override val defaultValue: String, ) : CommandValueParameter() { - override val type: KType get() = STRING_TYPE + public override val type: KType get() = STRING_TYPE + public override val defaultValue: Nothing? get() = null + public override val isOptional: Boolean get() = false private companion object { @OptIn(ExperimentalStdlibApi::class) @@ -64,6 +67,27 @@ public sealed class CommandValueParameter : ICommandParameter { } } + public class UserDefinedType( + public override val name: String, + public override val defaultValue: T?, + public override val isOptional: Boolean, + public override val type: KType, + ) : CommandValueParameter() { + public companion object { + @JvmStatic + public inline fun createOptional(name: String, defaultValue: T): UserDefinedType { + @OptIn(ExperimentalStdlibApi::class) + return UserDefinedType(name, defaultValue, true, typeOf()) + } + + @JvmStatic + public inline fun createRequired(name: String): UserDefinedType { + @OptIn(ExperimentalStdlibApi::class) + return UserDefinedType(name, null, false, typeOf()) + } + } + } + /** * Extended by [CommandValueArgumentParser] */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCall.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCall.kt index ef04564b1..4bb43bb9e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCall.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCall.kt @@ -14,8 +14,6 @@ package net.mamoe.mirai.console.command.parse import net.mamoe.mirai.console.command.Command import net.mamoe.mirai.console.command.CommandSender import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors -import net.mamoe.mirai.console.command.resolve.CommandCallResolver -import net.mamoe.mirai.console.util.ConsoleExperimentalApi /** * Unresolved [CommandCall]. @@ -33,10 +31,11 @@ public interface CommandCall { * Explicit value arguments */ public val valueArguments: List +} - /** - * Custom data for [CommandCallResolver] - */ - @ConsoleExperimentalApi - public val customData: Map -} \ No newline at end of file +@ExperimentalCommandDescriptors +public class CommandCallImpl( + override val caller: CommandSender, + override val calleeName: String, + override val valueArguments: List, +) : CommandCall \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallParserProvider.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallParserProvider.kt index d72aaa27c..a3870a932 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallParserProvider.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallParserProvider.kt @@ -15,7 +15,7 @@ import net.mamoe.mirai.console.extension.AbstractExtensionPoint import net.mamoe.mirai.console.extension.InstanceExtension /** - * The resolver for a [CommandCall] + * The provider of [CommandCallParser] */ @ExperimentalCommandDescriptors public interface CommandCallParserProvider : InstanceExtension {