Skip to content

Commit 68c2910

Browse files
author
凡辞
committed
feat: add sub-options to command info object provided by RegisterProvider
1 parent 548193e commit 68c2910

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/interfaces.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ export interface CommandParams {
2323
description?: string
2424
}
2525

26-
export type OptionType = BooleanConstructor | StringConstructor | NumberConstructor | ArrayConstructor
26+
export type OptionType = BooleanConstructor | StringConstructor | NumberConstructor | ArrayConstructor | [StringConstructor]
2727

2828
export interface OptionParams {
2929
name: string
3030
type?: OptionType
3131
description?: string
3232
alias?: string
3333
}
34+
35+
export interface RegisterCommandParams extends CommandParams {
36+
subOptions?: OptionParams[]
37+
}

src/services/register.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { OptionParams, CommandParams } from '../interfaces'
2-
1+
import { OptionParams, RegisterCommandParams } from '../interfaces'
32
export class RegisterProvider {
43
static isRegisterProvider: boolean = true
5-
4+
65
constructor(
7-
private _commands: CommandParams[] = [],
6+
private _commands: RegisterCommandParams[] = [],
87
private _options: OptionParams[] = [],
98
) {
109
}
11-
12-
get commands(): CommandParams[] {
10+
11+
get commands(): RegisterCommandParams[] {
1312
return this._commands
1413
}
15-
14+
1615
get options(): OptionParams[] {
1716
return this._options
1817
}
19-
18+
2019
}

src/utils/filter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { metadata } from '../constants/metadata'
44
export type OptionKeyValue = { [key: string]: string }
55

66
export const commandsToDatas = (commands: CommandClass[] = []) => {
7-
return commands.map(fn => Reflect.getMetadata(metadata.COMMAND_IDENTIFIER, fn))
7+
return commands.map(fn => Object.assign(
8+
Reflect.getMetadata(metadata.COMMAND_IDENTIFIER, fn),
9+
{ subOptions: Reflect.getMetadata(metadata.SUB_OPTION_IDENTIFIER, fn) || [] })
10+
)
811
}
912

1013
export const optionsToDatas = (options: OptionClass[]) => {

0 commit comments

Comments
 (0)