Commit 016e94bd authored by nanahira's avatar nanahira

add empty command

parent 15f13c1f
import { import {
CommandConfigExtended,
CommandDefinitionFun, CommandDefinitionFun,
CommandPutConfig, CommandPutConfig,
CommandPutConfigMap, CommandPutConfigMap,
...@@ -57,19 +58,19 @@ export const All = (path: string) => UseHttpRoute({ path, method: 'all' }); ...@@ -57,19 +58,19 @@ export const All = (path: string) => UseHttpRoute({ path, method: 'all' });
export function UseCommand<D extends string>( export function UseCommand<D extends string>(
def: D, def: D,
config?: Command.Config, config?: CommandConfigExtended,
): MethodDecorator; ): MethodDecorator;
export function UseCommand<D extends string>( export function UseCommand<D extends string>(
def: D, def: D,
desc: string, desc: string,
config?: Command.Config, config?: CommandConfigExtended,
): MethodDecorator; ): MethodDecorator;
export function UseCommand( export function UseCommand(
def: string, def: string,
...args: [Command.Config?] | [string, Command.Config?] ...args: [CommandConfigExtended?] | [string, CommandConfigExtended?]
): MethodDecorator { ): MethodDecorator {
const desc = typeof args[0] === 'string' ? (args.shift() as string) : ''; const desc = typeof args[0] === 'string' ? (args.shift() as string) : '';
const config = args[0] as Command.Config; const config = args[0] as CommandConfigExtended;
return (obj, key: string, des) => { return (obj, key: string, des) => {
const putOptions: CommandPutConfig<keyof CommandPutConfigMap>[] = const putOptions: CommandPutConfig<keyof CommandPutConfigMap>[] =
Reflect.getMetadata(KoishiCommandPutDef, obj.constructor, key) || Reflect.getMetadata(KoishiCommandPutDef, obj.constructor, key) ||
......
...@@ -119,10 +119,14 @@ export type DoRegisterConfig< ...@@ -119,10 +119,14 @@ export type DoRegisterConfig<
export interface CommandRegisterConfig<D extends string = string> { export interface CommandRegisterConfig<D extends string = string> {
def: D; def: D;
desc?: string; desc?: string;
config?: Command.Config; config?: CommandConfigExtended;
putOptions?: CommandPutConfig<keyof CommandPutConfigMap>[]; putOptions?: CommandPutConfig<keyof CommandPutConfigMap>[];
} }
export interface CommandConfigExtended extends Command.Config {
empty?: boolean;
}
export interface CommandOptionConfig { export interface CommandOptionConfig {
name: string; name: string;
desc: string; desc: string;
......
...@@ -269,20 +269,22 @@ export function KoishiPlugin<T = any>( ...@@ -269,20 +269,22 @@ export function KoishiPlugin<T = any>(
for (const commandDef of commandDefs) { for (const commandDef of commandDefs) {
command = commandDef(command) || command; command = commandDef(command) || command;
} }
if (!commandData.putOptions) { if (!commandData.config?.empty) {
command.action((argv: Argv, ...args: any[]) => if (!commandData.putOptions) {
this[methodKey](argv, ...args), command.action((argv: Argv, ...args: any[]) =>
); this[methodKey](argv, ...args),
} else {
for (const _optionToRegister of commandData.putOptions) {
this._preRegisterCommandActionArg(_optionToRegister, command);
}
command.action((argv: Argv, ...args: any[]) => {
const params = commandData.putOptions.map((o) =>
this._getCommandActionArg(o, argv, args),
); );
return this[methodKey](...params); } else {
}); for (const _optionToRegister of commandData.putOptions) {
this._preRegisterCommandActionArg(_optionToRegister, command);
}
command.action((argv: Argv, ...args: any[]) => {
const params = commandData.putOptions.map((o) =>
this._getCommandActionArg(o, argv, args),
);
return this[methodKey](...params);
});
}
} }
break; break;
case 'route': case 'route':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment