From 38c9a8ce9ed073d9f04b5ddde562f2d9bfe7e909 Mon Sep 17 00:00:00 2001 From: hypercross Date: Sat, 28 Feb 2026 17:20:48 +0800 Subject: [PATCH] fix: commander issues --- .../md-commander/hooks/useCommander.ts | 20 ++++++++++--------- src/components/md-commander/index.ts | 13 ++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 src/components/md-commander/index.ts diff --git a/src/components/md-commander/hooks/useCommander.ts b/src/components/md-commander/hooks/useCommander.ts index a53c3e8..4528783 100644 --- a/src/components/md-commander/hooks/useCommander.ts +++ b/src/components/md-commander/hooks/useCommander.ts @@ -12,18 +12,20 @@ export const defaultCommands: Record = { help: { command: "help", description: "显示帮助信息或特定命令的帮助", - options: { - cmd: { - option: "cmd", + parameters: [ + { + name: "cmd", description: "要查询的命令名", type: "enum", values: [], // 运行时填充 + required: false, }, - }, + ], handler: (args) => { - if (args.cmd) { + const cmdName = args.params.cmd; + if (cmdName) { return { - message: `命令:${args.cmd}\n描述:${defaultCommands[args.cmd]?.description || "无描述"}`, + message: `命令:${cmdName}\n描述:${defaultCommands[cmdName]?.description || "无描述"}`, type: "info", }; } @@ -286,9 +288,9 @@ export function useCommander( const commands = { ...defaultCommands, ...customCommands }; - // 更新 help 命令的选项值 - if (commands.help?.options?.cmd) { - commands.help.options.cmd.values = Object.keys(commands).filter( + // 更新 help 命令的参数值 + if (commands.help?.parameters?.[0]) { + commands.help.parameters[0].values = Object.keys(commands).filter( (k) => k !== "help", ); } diff --git a/src/components/md-commander/index.ts b/src/components/md-commander/index.ts new file mode 100644 index 0000000..fab9f89 --- /dev/null +++ b/src/components/md-commander/index.ts @@ -0,0 +1,13 @@ +export { CommanderInput } from './CommanderInput'; +export type { CommanderInputProps } from './CommanderInput'; +export { CommanderEntries } from './CommanderEntries'; +export type { CommanderEntriesProps } from './CommanderEntries'; +export type { + MdCommanderProps, + MdCommanderCommand, + MdCommanderOption, + MdCommanderParameter, + MdCommanderOptionType, + CommanderEntry, + CompletionItem, +} from './types';