Skip to content

Commit

Permalink
fix(koishi): support CJK option alias, fix #1424
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 16, 2024
1 parent eb7714a commit 605b1b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/command/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ export namespace Argv {
}
}

// do not use lookbehind assertion for Safari compatibility
const SYNTAX = /(?:-[\w\x80-\uffff-]*|[^,\s\w\x80-\uffff]+)/.source
const BRACKET = /((?:\s*\[[^\]]+?\]|\s*<[^>]+?>)*)/.source
const OPTION_REGEXP = new RegExp(`^(${SYNTAX}(?:,\\s*${SYNTAX})*(?=\\s|$))?${BRACKET}(.*)$`)

export class CommandBase<T extends CommandBase.Config = CommandBase.Config> {
public declaration: string

Expand All @@ -283,8 +288,7 @@ export namespace Argv {
}

_createOption(name: string, def: string, config: OptionConfig) {
// do not use lookbehind assertion for Safari compatibility
const cap = /^((?:-[\w-]*|[^,\s\w\x80-\uffff]+)(?:,\s*(?:-[\w-]*|[^,\s\w\x80-\uffff]+))*(?=\s|$))?((?:\s*\[[^\]]+?\]|\s*<[^>]+?>)*)(.*)$/.exec(def)
const cap = OPTION_REGEXP.exec(def)
const param = paramCase(name)
let syntax = cap[1] || '--' + param
const bracket = cap[2] || ''
Expand Down

0 comments on commit 605b1b7

Please sign in to comment.