@ismartify/inquirer
一个基于 @inquirer/prompts 的简单CLI工具构建库。
特性
- 🚀 简单易用:提供便捷方法快速添加命令
- 🎯 多种命令类型:确认命令、输入命令、选择命令
- 🔧 灵活配置:支持参数、选项、交互式执行
- 📦 零依赖:除了@inquirer外无其他依赖
安装
pnpm add @ismartify/inquirer
快速开始
import CLI from '@ismartify/inquirer';
const cli = new CLI('My CLI Tool');
cli.addConfirmCommand('clean', {
description: '清理项目(clean)',
message: '确定要清理项目吗?',
action: async function() {
console.log('正在清理...');
}
});
import { main } from '@ismartify/inquirer';
main(cli);
API
CLI类
构造函数
new CLI(title = 'CLI Tool')
方法
addCommand(name, config)
添加自定义命令。
cli.addCommand('command-name', {
description: '命令描述',
handler: async function() {
},
params: ['[param]'],
interactive: true,
options: ['verbose']
});
addConfirmCommand(name, config)
添加需要确认的命令。
cli.addConfirmCommand('clean', {
description: '清理项目(clean)',
message: '确定要执行吗?',
action: async function() {
}
});
addInputCommand(name, config)
添加需要输入参数的命令。
cli.addInputCommand('create', {
description: '创建项目(create)',
inputs: [
{ message: '项目名称:', default: 'my-project' }
],
action: async function(name) {
}
});
addSelectCommand(name, config)
添加选择命令。
cli.addSelectCommand('deploy', {
description: '部署项目(deploy)',
message: '选择环境:',
choices: [
{ name: '开发环境', value: 'dev' },
{ name: '生产环境', value: 'prod' }
],
action: async function(env) {
}
});
许可证
MIT