New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@ismartify/inquirer

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ismartify/inquirer

一个基于 [@inquirer/prompts](https://github.com/SBoudrias/Inquirer.js) 的简单CLI工具构建库。

npmnpm
Version
0.0.3
Version published
Maintainers
3
Created
Source

@ismartify/inquirer

一个基于 @inquirer/prompts 的简单CLI工具构建库。

特性

  • 🚀 简单易用:提供便捷方法快速添加命令
  • 🎯 多种命令类型:确认命令、输入命令、选择命令
  • 🔧 灵活配置:支持参数、选项、交互式执行
  • 📦 零依赖:除了@inquirer外无其他依赖

安装

pnpm add @ismartify/inquirer

快速开始

import CLI from '@ismartify/inquirer';

// 创建CLI实例
const cli = new CLI('My CLI Tool');

// 添加确认命令
cli.addConfirmCommand('clean', {
  description: '清理项目(clean)',
  message: '确定要清理项目吗?',
  action: async function() {
    console.log('正在清理...');
    // 执行清理逻辑
  }
});

// 启动CLI
import { main } from '@ismartify/inquirer';
main(cli);

API

CLI类

构造函数

new CLI(title = 'CLI Tool')
  • title: CLI工具的标题

方法

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) {
    // 使用name创建项目
  }
});
addSelectCommand(name, config)

添加选择命令。

cli.addSelectCommand('deploy', {
  description: '部署项目(deploy)',
  message: '选择环境:',
  choices: [
    { name: '开发环境', value: 'dev' },
    { name: '生产环境', value: 'prod' }
  ],
  action: async function(env) {
    // 部署到指定环境
  }
});

许可证

MIT

FAQs

Package last updated on 09 Oct 2025

Related posts