一个好用的命令行交互工具:ipt
Interactive Pipe To: The Node.js cli interactive workflow.
安装
npm i ipt
使用
const ipt = require("ipt");
const opts = {
stdin: process.stdin,
stdout: process.stdout,
message: "Select an item?",
autocomplete: false,
size: 3,
};
ipt(["option1", "option2", "option3", "option4", "option5"], opts).then((res) => {
console.log("res:", res[0]);
});