Skip to content

Commit

Permalink
feat(koishi): support fuzzy match between - and _
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 13, 2024
1 parent 29e8470 commit 6ef132b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/command/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ export class Command<
}
}

static normalize(name: string) {
return name.toLowerCase().replace(/_/g, '-')
}

private _registerAlias(name: string, prepend = false, options: Command.Alias = {}) {
name = name.toLowerCase()
name = Command.normalize(name)
if (name.startsWith('.')) name = this.parent.name + name

// check global
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class Commander {

_resolve(key: string) {
if (!key) return {}
const segments = key.toLowerCase().split('.')
const segments = Command.normalize(key).split('.')
let i = 1, name = segments[0], command: Command
while ((command = this.get(name)) && i < segments.length) {
name = command.name + '.' + segments[i++]
Expand Down Expand Up @@ -325,7 +325,7 @@ export class Commander {
command(def: string, ...args: [Command.Config?] | [string, Command.Config?]) {
const desc = typeof args[0] === 'string' ? args.shift() as string : ''
const config = args[0] as Command.Config
const path = def.split(' ', 1)[0].toLowerCase()
const path = Command.normalize(def.split(' ', 1)[0])
const decl = def.slice(path.length)
const segments = path.split(/(?=[./])/g)

Expand Down

0 comments on commit 6ef132b

Please sign in to comment.