Skip to content

Commit

Permalink
fix(core): re-parse redirected commands, fix koishijs#540
Browse files Browse the repository at this point in the history
  • Loading branch information
Anillc committed May 2, 2022
1 parent 99f886b commit 33bdc40
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/src/internal/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,20 @@ export default function runtime(ctx: Context) {
}

if (command['_actions'].length) return
// subcommand redirect
const arg0 = args.shift() || ''
const subcommand = ctx.getCommand(command.name + '.' + arg0)
if (subcommand) {
// save command names
const commands = session['__redirected_commands'] ||= [
`(${command.name}${command._aliases.length !== 0 ? '|' + command._aliases.join('|') : ''})`,
]
commands.push(arg0)
const regex = new RegExp(`^${commands.join('[. ]')}( |$)`)
// remove command names for re-parsing
argv = Argv.parse(session.parsed.content.replace(regex, ''))
argv.session = session
argv = subcommand.parse(argv)
return session.execute({ ...argv, command: subcommand })
} else {
return executeHelp(session, command.name)
Expand Down

0 comments on commit 33bdc40

Please sign in to comment.