#!/usr/bin/env node
console.log('hello world');
$ chmod 755 ./bin/helper
$ ./bin/helper hello world
{
"name": "helper",
"bin": {
"helper": "bin/helper"
}
}
$ npm link /node_path/bin/helper -> /node_path/lib/node_modules/myModule/bin/helper /node_path/lib/node_modules/myModule -> /Users/ipluser/myModule
$ helper hello world
$ npm install --save commander
#!/usr/bin/env node
var program = require('commander');
program
.version('1.0.0')
.parse(process.argv);
$ helper -h Usage: helper [options] Options: -h, --help output usage information -V, --version output the version number $ helper -V 1.0.0
#!/usr/bin/env node
var program = require('commander');
program
.version('1.0.0')
.usage('<command> [options]')
.command('hello', 'hello the author') // 添加hello命令
.parse(process.argv);
#!/usr/bin/env node
console.log('hello author');
$ helper hello ipluser hello author
#!/usr/bin/env node
var program = require('commander');
program.parse(process.argv);
const author = program.args[0];
console.log('hello', author);
$ helper hello ipluser hello ipluser
#!/usr/bin/env node
var program = require('commander');
program.usage('<author>');
// 用户输入`helper hello -h`或`helper hello --helper`时,显示命令使用例子
program.on('--help', function() {
console.log(' Examples:');
console.log(' $ helper hello ipluser');
console.log();
});
program.parse(process.argv);
(program.args.length < 1) && program.help(); // 用户没有输入信息时,调用`help`方法显示帮助信息
const author = program.args[0];
console.log('hello', author);
$ helper hello Usage: helper-hello <author> Options: -h, --help output usage information Examples: $ helper hello ipluser $ helper hello -h Usage: helper-hello <author> Options: -h, --help output usage information Examples: $ helper hello ipluser
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有