Skip to content

Commit

Permalink
fix(core): strip type for command decl, fix #148
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 8, 2021
1 parent 3f62c59 commit a1b8b98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/koishi-core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,19 @@ export namespace Domain {
type OptionDeclarationMap = Record<string, OptionDeclaration>

export class CommandBase {
public declaration: string

public _arguments: Declaration[]
public _options: OptionDeclarationMap = {}

private _error: string
private _namedOptions: OptionDeclarationMap = {}
private _symbolicOptions: OptionDeclarationMap = {}

constructor(public name: string, public declaration: string, public description: string) {
constructor(public name: string, declaration: string, public description: string) {
if (!name) throw new Error('expect a command name')
this._arguments = parseDecl(declaration)
const decl = this._arguments = parseDecl(declaration)
this.declaration = decl.stripped
}

_createOption(name: string, def: string, config?: OptionConfig) {
Expand Down
4 changes: 2 additions & 2 deletions packages/koishi-core/tests/help.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ describe('Help Command', () => {

it('command options', async () => {
const bar = app
.command('bar', 'DESCRIPTION', { maxUsage: 2, hideOptions: true })
.command('bar <arg:number>', 'DESCRIPTION', { maxUsage: 2, hideOptions: true })
.option('opt1', '选项1', { authority: 2 })
.option('opt2', '选项2', { notUsage: true })
.option('opt3', '选项3', { hidden: true })

await session.shouldReply('help bar', message = 'bar\nDESCRIPTION\n已调用次数:0/2。')
await session.shouldReply('help bar', message = 'bar <arg>\nDESCRIPTION\n已调用次数:0/2。')

bar.config.hideOptions = false

Expand Down

0 comments on commit a1b8b98

Please sign in to comment.