diff --git a/packages/core/src/command/command.ts b/packages/core/src/command/command.ts index 2aa39d1c5..16be10af1 100644 --- a/packages/core/src/command/command.ts +++ b/packages/core/src/command/command.ts @@ -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 diff --git a/packages/core/src/command/index.ts b/packages/core/src/command/index.ts index 7a072f142..d330e672c 100644 --- a/packages/core/src/command/index.ts +++ b/packages/core/src/command/index.ts @@ -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++] @@ -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)