mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { authCommand } from './auth'
|
|
import { claudeCommand } from './claude'
|
|
import { codexCommand } from './codex'
|
|
import { connectCommand } from './connect'
|
|
import { daemonCommand } from './daemon'
|
|
import { doctorCommand } from './doctor'
|
|
import { geminiCommand } from './gemini'
|
|
import { hookForwarderCommand } from './hookForwarder'
|
|
import { mcpCommand } from './mcp'
|
|
import { notifyCommand } from './notify'
|
|
import { serverCommand } from './server'
|
|
import type { CommandContext, CommandDefinition } from './types'
|
|
|
|
const COMMANDS: CommandDefinition[] = [
|
|
authCommand,
|
|
connectCommand,
|
|
codexCommand,
|
|
geminiCommand,
|
|
mcpCommand,
|
|
serverCommand,
|
|
hookForwarderCommand,
|
|
doctorCommand,
|
|
daemonCommand,
|
|
notifyCommand
|
|
]
|
|
|
|
const commandMap = new Map<string, CommandDefinition>()
|
|
for (const command of COMMANDS) {
|
|
commandMap.set(command.name, command)
|
|
}
|
|
|
|
export function resolveCommand(args: string[]): { command: CommandDefinition; context: CommandContext } {
|
|
const subcommand = args[0]
|
|
const command = subcommand ? commandMap.get(subcommand) : undefined
|
|
const resolvedCommand = command ?? claudeCommand
|
|
const commandArgs = command ? args.slice(1) : args
|
|
|
|
return {
|
|
command: resolvedCommand,
|
|
context: {
|
|
args,
|
|
subcommand,
|
|
commandArgs
|
|
}
|
|
}
|
|
}
|