feat: add api doc

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2020-03-24 17:59:18 +08:00
parent f5a7a269e4
commit 73b9c2f163
4 changed files with 69 additions and 9 deletions

View File

@ -4,6 +4,12 @@ import { injectable } from "@ms/container";
export namespace command {
@injectable()
export abstract class Command {
/**
* 注册插件命令
* @param plugin 插件
* @param name 命令
* @param exec 执行器
*/
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
var cmd = this.create(plugin, name);
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
@ -16,18 +22,20 @@ export namespace command {
this.onTabComplete(plugin, cmd, exec.tab);
}
}
/**
* 取消命令注册
* @param plugin 插件
* @param name 命令
*/
off(plugin: any, name: string) {
console.debug(i18n.translate("ms.api.command.unregister", { plugin: plugin.description.name, name }))
this.remove(plugin, name);
}
/**
* Create Server Command Object
*/
protected abstract create(plugin: any, command: string);
protected abstract remove(plugin: any, command: string);
protected abstract onCommand(plugin: any, command: any, executor: Function);
protected abstract onTabComplete(plugin: any, command: any, tabCompleter: Function);
protected setExecutor(plugin: any, command: any, executor: Function) {
return (sender: any, _: any, command: string, args: string[]) => {
try {
@ -40,7 +48,6 @@ export namespace command {
}
}
}
protected setTabCompleter(plugin: any, command: any, tabCompleter: Function) {
return (sender: any, _: any, command: string, args: string[]) => {
try {
@ -55,10 +62,9 @@ export namespace command {
}
}
}
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
if (!token) { return complete }
complete.forEach(function(e) {
complete.forEach(function (e) {
if (typeof e === "string" && e.toLowerCase().startsWith(token.toLowerCase())) {
array.push(e)
}