program .version('0.1.0') .command('create <name>') .description('create a new project') .action(name => { // 打印命令行输入的值 console.log("project name is " + name) })
program.parse()
命令行输出内容
1 2 3 4 5 6 7 8 9 10 11
~/Desktop/my-cli/my-cli
Usage: my-cli [options] [command]
Options: -V, --version output the version number -h, --help display help for command
Commands: create <name> create a new project help [command] display help for command
const program = require('commander') const chalk = require('chalk')
program .version('0.1.0') .command('create <name>') .description('create a new project') .action(name => { // 文本样式 console.log("project name is " + chalk.bold(name)) // 颜色 console.log("project name is " + chalk.cyan(name)) console.log("project name is " + chalk.green(name)) // 背景色 console.log("project name is " + chalk.bgRed(name)) // 使用RGB颜色输出 console.log("project name is " + chalk.rgb(4, 156, 219).underline(name)); console.log("project name is " + chalk.hex('#049CDB').bold(name)); console.log("project name is " + chalk.bgHex('#049CDB').bold(name)) })