(program: Command)
| 10 | * 工具相关命令 |
| 11 | */ |
| 12 | export function toolsCommand(program: Command): void { |
| 13 | const toolsCmd = program.command('tools').description('🔧 工具管理和操作'); |
| 14 | |
| 15 | // 列出所有工具 |
| 16 | toolsCmd |
| 17 | .command('list') |
| 18 | .description('列出所有可用工具') |
| 19 | .option('-c, --category <category>', '按分类过滤') |
| 20 | .option('-s, --search <query>', '搜索工具') |
| 21 | .option('--format <format>', '输出格式', 'table') |
| 22 | .action(async options => { |
| 23 | const spinner = UIProgress.spinner('正在加载工具列表...'); |
| 24 | spinner.start(); |
| 25 | |
| 26 | try { |
| 27 | const toolManager = await createToolManager(); |
| 28 | let tools = toolManager.getTools(); |
| 29 | |
| 30 | // 分类过滤 |
| 31 | if (options.category) { |
| 32 | tools = tools.filter( |
| 33 | tool => tool.category?.toLowerCase() === options.category.toLowerCase() |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | // 搜索过滤 |
| 38 | if (options.search) { |
| 39 | const query = options.search.toLowerCase(); |
| 40 | tools = tools.filter( |
| 41 | tool => |
| 42 | tool.name.toLowerCase().includes(query) || |
| 43 | tool.description.toLowerCase().includes(query) || |
| 44 | (tool.tags && tool.tags.some(tag => tag.toLowerCase().includes(query))) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | spinner.succeed('工具列表加载完成'); |
| 49 | |
| 50 | if (tools.length === 0) { |
| 51 | UIDisplay.warning('未找到匹配的工具'); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if (options.format === 'json') { |
| 56 | console.log(JSON.stringify(tools, null, 2)); |
| 57 | } else { |
| 58 | displayToolsTable(tools); |
| 59 | } |
| 60 | } catch (error: any) { |
| 61 | spinner.fail('工具列表获取失败'); |
| 62 | UIDisplay.error(`错误: ${error.message}`); |
| 63 | } |
| 64 | }); |
| 65 | |
| 66 | // 查看工具详情 |
| 67 | toolsCmd |
| 68 | .command('info <toolName>') |
| 69 | .description('查看工具详细信息') |
no test coverage detected