fix: commander issues

This commit is contained in:
hypercross 2026-02-28 17:20:48 +08:00
parent 28066c7fff
commit 38c9a8ce9e
2 changed files with 24 additions and 9 deletions

View File

@ -12,18 +12,20 @@ export const defaultCommands: Record<string, MdCommanderCommand> = {
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",
);
}

View File

@ -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';