Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: 当给 option 设置了 fallback 后,alias 中的 config.options 无效 #1437

Closed
SaarChaffee opened this issue Aug 7, 2024 · 1 comment
Labels
bug BUG

Comments

@SaarChaffee
Copy link
Member

Describe the bug

当给 option 设置了 fallback 后,alias 中的 config.options 无效

Steps to reproduce

ctx
  .command('cmd <cmd:string>')
  .option('region', '-r <region:string>', { fallback: 'cn' })
  .alias('tcmd', { options: { region: 'tw' } })
  .alias('rcmd', { options: { region: 'jp' } })
  .action(async ({ session, options }, cmd) => {
    ctx.logger.info(cmd)
    ctx.logger.info(options)
  })
message: [ '#cmd 123' ]
cmd: 123
option: { region: 'cn' }

message: [ '#tcmd123' ]
cmd: 123
option: { region: 'cn' }

message: [ '#rcmd 123' ]
cmd: 123
option: { region: 'cn' }

Expected behavior

region 应该与 alias 中传入的一致

Screenshots

No response

Versions

System:
OS: Windows 10 10.0.19045
CPU: (8) x64 Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz

Binaries:
Node: 22.5.1
Yarn: 4.1.1

Koishi:
Core: 4.17.10
Console: 5.29.3

Additional context

No response

@SaarChaffee SaarChaffee added the bug BUG label Aug 7, 2024
@shigma shigma closed this as completed in 62332c3 Aug 7, 2024
@Hieuzest
Copy link

Hieuzest commented Aug 8, 2024

Currently the pre-defined args of aliases is broken by the fix.

argv.options = { ...argv.options, ...options }
argv.args = [...argv.args || [], ...args]

should be pure re-assignment to avoid redundant, and

const args = argv.args || []

should be [...argv.args] otherwise it will modify alias definition

@Hieuzest Hieuzest reopened this Aug 8, 2024
@shigma shigma closed this as completed in 29e8470 Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug BUG
Projects
None yet
Development

No branches or pull requests

2 participants