(三)node 命令行 inquirer
2022/2/6 17:14:01
本文主要是介绍(三)node 命令行 inquirer,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Inquirer:问答式
inquirer.js —— 一个用户与命令行交互的工具_xhsdnn的专栏-CSDN博客_inquirer
#! /usr/bin/env node const program = require('commander') const shell = require('shelljs') const path = require('path') const inquirer = require('inquirer') // 该命令的版本 program.version('1.0.0') const runQuestion = () => { const promptList = [{ type: 'input', message: '设置一个用户名:', name: 'name', default: "test_user" // 默认值 }, { type: 'input', message: '请输入手机号:', name: 'phone', validate: function (val) { if (val.match(/\d{11}/g)) { // 校验位数 return true // 如果校验通过要返回 true } else { // 校验不通过返回 string 类型的error 信息 return "请输入11位数字" } } }] inquirer.prompt(promptList).then((res) => { console.log(res, 'answers') }) } // 该命令的不同动作(指令) program .command('run') // run 命令 .description('运行项目') // 描述 .action(runQuestion) // 解析命令行传入的参数-找到其对应的指令 program.parse(process.avg)
then 函数 返回一个 问答对象
这篇关于(三)node 命令行 inquirer的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-19环境变量处理课程:新手入门教程
- 2024-09-19接口模块封装课程:新手入门指南
- 2024-09-19请求动作封装课程:新手入门教程
- 2024-09-19拖拽表格课程:新手入门指南
- 2024-09-19页面权限课程:新手必学的权限管理入门教程
- 2024-09-19如何正确主动登出课程:新手必读教程
- 2024-09-19Element-Plus课程:新手入门与初级教程
- 2024-09-19Token处理入门教程:新手必看指南
- 2024-09-19如何应对被动登出课程的情况:新手必读指南
- 2024-09-19打包优化课程:初学者的必备指南