-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
434 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
mirai-console/backend/mirai-console/src/command/AbstractSubCommandGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2019-2022 Mamoe Technologies and contributors. | ||
* | ||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. | ||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. | ||
* | ||
* https://github.com/mamoe/mirai/blob/dev/LICENSE | ||
*/ | ||
|
||
package net.mamoe.mirai.console.command | ||
|
||
import net.mamoe.mirai.console.command.descriptor.* | ||
import net.mamoe.mirai.console.internal.command.GroupedCommandSubCommandAnnotationResolver | ||
import net.mamoe.mirai.console.internal.command.SubCommandReflector | ||
|
||
public abstract class AbstractSubCommandGroup( | ||
overrideContext: CommandArgumentContext = EmptyCommandArgumentContext, | ||
) : CommandArgumentContextAware, SubCommandGroup { | ||
|
||
private val reflector by lazy { SubCommandReflector(this, GroupedCommandSubCommandAnnotationResolver) } | ||
|
||
@ExperimentalCommandDescriptors | ||
public final override val overloads: List<CommandSignatureFromKFunction> by lazy { | ||
reflector.findSubCommands().also { | ||
reflector.validate(it) | ||
} | ||
} | ||
|
||
/** | ||
* 智能参数解析环境 | ||
*/ // open since 2.12 | ||
public override val context: CommandArgumentContext = CommandArgumentContext.Builtins + overrideContext | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
mirai-console/backend/mirai-console/src/command/SubCommandGroup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.mamoe.mirai.console.command | ||
|
||
import net.mamoe.mirai.console.command.descriptor.CommandSignatureFromKFunction | ||
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors | ||
import net.mamoe.mirai.console.compiler.common.ResolveContext | ||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi | ||
|
||
public interface SubCommandGroup { | ||
|
||
/** | ||
* 被聚合时提供的子指令 | ||
*/ | ||
@ExperimentalCommandDescriptors | ||
public val overloads: List<@JvmWildcard CommandSignatureFromKFunction> | ||
|
||
/** | ||
* 标记一个属性为子指令集合,且使用flat策略 | ||
*/ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.PROPERTY) | ||
public annotation class FlattenSubCommands( | ||
) | ||
|
||
/** | ||
* 1. 标记一个函数为子指令, 当 [value] 为空时使用函数名. | ||
* 2. 标记一个属性为子指令集合,且使用sub策略 | ||
* @param value 子指令名 | ||
*/ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) | ||
public annotation class SubCommand( | ||
@ResolveContext(ResolveContext.Kind.COMMAND_NAME) vararg val value: String = [], | ||
) | ||
|
||
/** 指令描述 */ | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.FUNCTION) | ||
public annotation class Description(val value: String) | ||
|
||
/** 参数名, 由具体Command决定用途 */ | ||
@ConsoleExperimentalApi("Classname might change") | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.VALUE_PARAMETER) | ||
public annotation class Name(val value: String) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.