Skip to content

Commit

Permalink
fix(core): enhance spacing for command option decl, fix #148
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 8, 2021
1 parent a1b8b98 commit 72eb362
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/koishi-core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,15 @@ export namespace Domain {
}

const declList = parseDecl(bracket)
if (declList.stripped) syntax += ' ' + declList.stripped
if (desc) syntax += ' ' + desc
const option = this._options[name] ||= {
...Command.defaultOptionConfig,
...declList[0],
...config,
name,
values: {},
description: syntax + ' ' + declList.stripped + desc,
description: syntax,
}

if ('value' in config) {
Expand Down
6 changes: 4 additions & 2 deletions packages/koishi-core/tests/help.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe('Help Command', () => {
.command('bar <arg:number>', 'DESCRIPTION', { maxUsage: 2, hideOptions: true })
.option('opt1', '选项1', { authority: 2 })
.option('opt2', '选项2', { notUsage: true })
.option('opt3', '选项3', { hidden: true })
.option('opt3', '[arg:boolean] 选项3', { hidden: true })
.option('opt4', '-o [arg:boolean]', { hidden: true })

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

Expand All @@ -91,7 +92,8 @@ describe('Help Command', () => {
' -h, --help 显示此信息',
' --opt1 选项1',
' --opt2 选项2(不计入总次数)',
' --opt3 选项3',
' --opt3 [arg] 选项3',
' -o, --opt4 [arg]',
].join('\n'))

await session.shouldReply('help bar -a', [
Expand Down

0 comments on commit 72eb362

Please sign in to comment.