feat: update plugin register

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-11-04 20:28:52 +08:00
parent 83cc4b6a54
commit 736760b2ee
3 changed files with 6 additions and 5 deletions

View File

@ -35,12 +35,13 @@ export function cmd(metadata: interfaces.CommandMetadata = {}) {
} }
/** /**
* MiaoScript Command * MiaoScript TabComplete
* @param metadata CommandMetadata * @param metadata TabCompleterMetadata
*/ */
export function tab(metadata: interfaces.TabCompleterMetadata = {}) { export function tab(metadata: interfaces.TabCompleterMetadata = {}) {
return function(target: any, key: string, value: any) { return function(target: any, key: string, value: any) {
metadata.name = metadata.name || key.startsWith('tab') ? key.split('tab', 2)[0] : key; metadata.name = metadata.name || (key.startsWith('tab') ? key.split('tab', 2)[1] : key);
if (!metadata.name) { return; }
metadata.executor = key; metadata.executor = key;
metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key) metadata.paramtypes = Reflect.getMetadata("design:paramtypes", target, key)
const previousMetadata: Map<string, interfaces.TabCompleterMetadata> = getPluginTabCompleterMetadata(target) const previousMetadata: Map<string, interfaces.TabCompleterMetadata> = getPluginTabCompleterMetadata(target)

View File

@ -1,4 +1,4 @@
import { injectable, postConstruct } from "inversify"; import { injectable } from "@ms/container";
export namespace interfaces { export namespace interfaces {
@injectable() @injectable()

View File

@ -34,7 +34,7 @@ function getPluginCommandMetadata(target: any) {
} }
function getPluginTabCompleterMetadata(target: any) { function getPluginTabCompleterMetadata(target: any) {
let tabcompleterMetadata: Map<string, interfaces.CommandMetadata> = Reflect.getMetadata( let tabcompleterMetadata: Map<string, interfaces.TabCompleterMetadata> = Reflect.getMetadata(
METADATA_KEY.tab, METADATA_KEY.tab,
target.constructor target.constructor
) || new Map<string, interfaces.TabCompleterMetadata>(); ) || new Map<string, interfaces.TabCompleterMetadata>();