# Commander.js
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/visionmedia/commander).
[![Build Status](https://secure.travis-ci.org/visionmedia/commander.js.png)](http://travis-ci.org/visionmedia/commander.js)
## Installation
$ npm install commander
## Option parsing
Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
program
.version('0.0.1')
.option('-p, --peppers', 'Add peppers')
.option('-P, --pineapple', 'Add pineapple')
.option('-b, --bbq', 'Add bbq sauce')
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
.parse(process.argv);
console.log('you ordered a pizza with:');
if (program.peppers) console.log(' - peppers');
if (program.pineapple) console.log(' - pineapple');
if (program.bbq) console.log(' - bbq');
console.log(' - %s cheese', program.cheese);
```
Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.
## Automated --help
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
```
$ ./examples/pizza --help
Usage: pizza [options]
Options:
-V, --version output the version number
-p, --peppers Add peppers
-P, --pineapple Add pineapple
-b, --bbq Add bbq sauce
-c, --cheese <type> Add the specified type of cheese [marble]
-h, --help output usage information
```
## Coercion
```js
function range(val) {
return val.split('..').map(Number);
}
function list(val) {
return val.split(',');
}
program
.version('0.0.1')
.usage('[options] <file ...>')
.option('-i, --integer <n>', 'An integer argument', parseInt)
.option('-f, --float <n>', 'A float argument', parseFloat)
.option('-r, --range <a>..<b>', 'A range', range)
.option('-l, --list <items>', 'A list', list)
.option('-o, --optional [value]', 'An optional value')
.parse(process.argv);
console.log(' int: %j', program.integer);
console.log(' float: %j', program.float);
console.log(' optional: %j', program.optional);
program.range = program.range || [];
console.log(' range: %j..%j', program.range[0], program.range[1]);
console.log(' list: %j', program.list);
console.log(' args: %j', program.args);
```
## Custom help
You can display arbitrary `-h, --help` information
by listening for "--help". Commander will automatically
exit once you are done so that the remainder of your program
does not execute causing undesired behaviours, for example
in the following executable "stuff" will not output when
`--help` is used.
```js
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('../');
function list(val) {
return val.split(',').map(Number);
}
program
.version('0.0.1')
.option('-f, --foo', 'enable some foo')
.option('-b, --bar', 'enable some bar')
.option('-B, --baz', 'enable some baz');
// must be before .parse() since
// node's emit() is immediate
program.on('--help', function(){
console.log(' Examples:');
console.log('');
console.log(' $ custom-help --help');
console.log(' $ custom-help -h');
console.log('');
});
program.parse(process.argv);
console.log('stuff');
```
yielding the following help output:
```
Usage: custom-help [options]
Options:
-h, --help output usage information
-V, --version output the version number
-f, --foo enable some foo
-b, --bar enable some bar
-B, --baz enable some baz
Examples:
$ custom-help --help
$ custom-help -h
```
## .prompt(msg, fn)
Single-line prompt:
```js
program.prompt('name: ', function(name){
console.log('hi %s', name);
});
```
Multi-line prompt:
```js
program.prompt('description:', function(name){
console.log('hi %s', name);
});
```
Coercion:
```js
program.prompt('Age: ', Number, function(age){
console.log('age: %j', age);
});
```
```js
program.prompt('Birthdate: ', Date, function(date){
console.log('date: %s', date);
});
```
```js
program.prompt('Email: ', /^.+@.+\..+$/, function(email){
console.log('email: %j', email);
});
```
## .password(msg[, mask], fn)
Prompt for password without echoing:
```js
program.password('Password: ', function(pass){
console.log('got "%s"', pass);
process.stdin.destroy();
});
```
Prompt for password with mask char "*":
```js
program.password('Password: ', '*', function(pass){
console.log('got "%s"', pass);
process.stdin.destroy();
});
```
## .confirm(msg, fn)
Confirm with the given `msg`:
```js
program.confirm('continue? ', function(ok){
console.log(' got %j', ok);
});
```
## .choose(list, fn)
Let the user choose from a `list`:
```js
var list = ['tobi', 'loki', 'jane', 'manny', 'luna'];
console.log('Choose the coolest pet:');
program.choose(list, function(i){
console.log('you chose %d "%s"', i, list[i]);
});
```
## .outputHelp()
Output help information without exiting.
## .help()
Output help information and exit immediately.
## Links
- [API documentation](http://visionmedia.github.com/commander.js/)
- [ascii tables](https://github.com/LearnBoost/cli-table)
- [progress bars](https://github.com/visionmedia/node-progress)
- [more progress bars](https://github.com/substack/node-multimeter)
- [examples](https://github.com/visionmedia/commander.js/tree/master/examples)
## License
(The MIT License)
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
没有合适的资源?快使用搜索试试~ 我知道了~
typescript使用nodejs实现简繁体转换
共606个文件
js:212个
png:93个
md:72个
5星 · 超过95%的资源 需积分: 50 65 下载量 38 浏览量
2014-05-24
11:49:10
上传
评论
收藏 3.96MB RAR 举报
温馨提示
typescript使用nodejs实现简繁体转换,可以转换子文件夹, 运行方式:将文件复制到工程的files文件夹,运行node app.js "" s2t(简体转繁体)或node app.js "" t2s(繁体转简体)即可
资源推荐
资源详情
资源评论
收起资源包目录
typescript使用nodejs实现简繁体转换 (606个子文件)
DesignTimeResolveAssemblyReferencesInput.cache 69KB
CNAME 17B
TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs 0B
TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs 0B
TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs 0B
openCC.csproj 64KB
style.css 5KB
style.css 602B
express 9KB
blank.gif 49B
.gitmodules 207B
binaryfile.tar.gz 301B
index.html 88KB
directory.html 2KB
error.html 276B
form.html 224B
pf1y5.png.http 751KB
beta-sticker-1.png.http 3KB
menu_seperator.png.http 2KB
osx-chrome-13.http 1KB
osx-firefox-3.6.http 977B
xp-chrome-12.http 945B
osx-safari-5.http 920B
xp-safari-5.http 881B
binaryfile.tar.gz.http 850B
xp-ie-8.http 833B
xp-ie-7.http 820B
blank.gif.http 497B
preamble.http 365B
filename-name.http 362B
generic.http 353B
plain.txt.http 352B
crlf.http 323B
missing-hyphens1.http 319B
missing-hyphens2.http 319B
favicon.ico 1KB
favicon.ico 1KB
docs.jade 1KB
toml.jison 4KB
tobi.jpeg 36KB
wind-compiler.js 117KB
transation.js 71KB
underscore.js 40KB
wind-async.js 26KB
_stream_readable.js 25KB
index.js 25KB
response.js 19KB
toml.js 18KB
index.js 16KB
wind-builderbase.js 13KB
underscore-min.js 13KB
_stream_writable.js 13KB
index.js 13KB
send.js 12KB
application.js 12KB
request.js 12KB
index.js 10KB
wind-core.js 9KB
utils.js 8KB
parse.js 7KB
index.js 7KB
_stream_transform.js 7KB
index.js 7KB
utils.js 7KB
index.js 6KB
index.js 6KB
proto.js 6KB
staticCache.js 6KB
session.js 6KB
index.js 6KB
index.js 5KB
multipart.js 5KB
index.js 5KB
index.js 4KB
build.js 4KB
index.js 4KB
index.js 4KB
cookieSession.js 3KB
index.js 3KB
test.js 3KB
patch.js 3KB
wind-promise.js 3KB
index.js 3KB
util.js 3KB
util.js 3KB
mime.js 3KB
index.js 3KB
_stream_duplex.js 3KB
app.js 3KB
test.js 3KB
index.js 3KB
index.js 3KB
index.js 3KB
debug.js 3KB
debug.js 3KB
encoding.js 2KB
encoding.js 2KB
index.js 2KB
debug.js 2KB
debug.js 2KB
共 606 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
- 临风Code2018-04-19感谢分享, 赞一个
- Jaybobo9102016-05-11东西下载了 应该不错,用过后再评论
o6875461
- 粉丝: 0
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于ESP8266的WebDAV服务器与3D打印机管理系统.zip
- (源码)基于Nio实现的Mycat 2.0数据库代理系统.zip
- (源码)基于Java的高校学生就业管理系统.zip
- (源码)基于Spring Boot框架的博客系统.zip
- (源码)基于Spring Boot框架的博客管理系统.zip
- (源码)基于ESP8266和Blynk的IR设备控制系统.zip
- (源码)基于Java和JSP的校园论坛系统.zip
- (源码)基于ROS Kinetic框架的AGV激光雷达导航与SLAM系统.zip
- (源码)基于PythonDjango框架的资产管理系统.zip
- (源码)基于计算机系统原理与Arduino技术的学习平台.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功