opal 1.6.0 → 1.7.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +17 -0
- data/CHANGELOG.md +15 -1
- data/Gemfile +2 -0
- data/HACKING.md +47 -26
- data/UNRELEASED.md +27 -0
- data/benchmark/benchmarks +415 -103
- data/benchmark/bm_call_overhead.yml +28 -0
- data/benchmark/run.rb +61 -40
- data/docs/cdp_common.json +3364 -0
- data/docs/cdp_common.md +18 -0
- data/docs/{headless_chrome.md → headless_browsers.md} +31 -12
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/builder.rb +8 -2
- data/lib/opal/builder_processors.rb +5 -3
- data/lib/opal/builder_scheduler.rb +1 -1
- data/lib/opal/cache.rb +1 -7
- data/lib/opal/cli_options.rb +72 -58
- data/lib/opal/cli_runners/chrome.rb +47 -9
- data/lib/opal/cli_runners/chrome_cdp_interface.rb +238 -112
- data/lib/opal/cli_runners/compiler.rb +146 -13
- data/lib/opal/cli_runners/deno.rb +32 -0
- data/lib/opal/cli_runners/firefox.rb +350 -0
- data/lib/opal/cli_runners/firefox_cdp_interface.rb +212 -0
- data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.cmd +17 -0
- data/lib/opal/cli_runners/node_modules/.bin/chrome-remote-interface.ps1 +28 -0
- data/lib/opal/cli_runners/node_modules/.package-lock.json +41 -0
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/LICENSE +1 -1
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/README.md +322 -182
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/bin/client.js +99 -114
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/chrome-remote-interface.js +1 -11
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/index.js +16 -11
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/api.js +41 -33
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/chrome.js +224 -214
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/devtools.js +71 -191
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/external-request.js +26 -6
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/protocol.json +20788 -9049
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +10 -3
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/package.json +59 -123
- data/lib/opal/cli_runners/node_modules/chrome-remote-interface/webpack.config.js +25 -32
- data/lib/opal/cli_runners/node_modules/commander/History.md +298 -0
- data/lib/opal/cli_runners/node_modules/commander/LICENSE +22 -0
- data/lib/opal/cli_runners/node_modules/commander/Readme.md +217 -61
- data/lib/opal/cli_runners/node_modules/commander/index.js +431 -145
- data/lib/opal/cli_runners/node_modules/commander/package.json +16 -79
- data/lib/opal/cli_runners/node_modules/ws/README.md +334 -98
- data/lib/opal/cli_runners/node_modules/ws/browser.js +8 -0
- data/lib/opal/cli_runners/node_modules/ws/index.js +5 -10
- data/lib/opal/cli_runners/node_modules/ws/lib/buffer-util.js +129 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/constants.js +10 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/event-target.js +184 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/extension.js +223 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/limiter.js +55 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/permessage-deflate.js +518 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/receiver.js +607 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/sender.js +409 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/stream.js +180 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/validation.js +104 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/websocket-server.js +447 -0
- data/lib/opal/cli_runners/node_modules/ws/lib/websocket.js +1195 -0
- data/lib/opal/cli_runners/node_modules/ws/package.json +40 -106
- data/lib/opal/cli_runners/package-lock.json +62 -0
- data/lib/opal/cli_runners/package.json +1 -1
- data/lib/opal/cli_runners.rb +26 -4
- data/lib/opal/nodes/args/prepare_post_args.rb +2 -2
- data/lib/opal/nodes/def.rb +8 -8
- data/lib/opal/nodes/iter.rb +12 -12
- data/lib/opal/nodes/logic.rb +1 -1
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/paths.rb +14 -0
- data/lib/opal/rewriter.rb +2 -0
- data/lib/opal/rewriters/forward_args.rb +52 -4
- data/lib/opal/rewriters/targeted_patches.rb +94 -0
- data/lib/opal/version.rb +1 -1
- data/opal/corelib/basic_object.rb +1 -1
- data/opal/corelib/boolean.rb +2 -2
- data/opal/corelib/class.rb +11 -0
- data/opal/corelib/constants.rb +3 -3
- data/opal/corelib/enumerable.rb +4 -0
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/hash.rb +2 -2
- data/opal/corelib/helpers.rb +1 -1
- data/opal/corelib/kernel.rb +3 -3
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +29 -8
- data/opal/corelib/proc.rb +7 -5
- data/opal/corelib/runtime.js +141 -78
- data/opal/corelib/set.rb +252 -0
- data/opal/corelib/string.rb +2 -1
- data/opal/corelib/time.rb +2 -2
- data/opal/opal.rb +1 -0
- data/opal.gemspec +1 -0
- data/spec/filters/bugs/array.rb +22 -13
- data/spec/filters/bugs/base64.rb +5 -5
- data/spec/filters/bugs/basicobject.rb +16 -8
- data/spec/filters/bugs/bigdecimal.rb +161 -160
- data/spec/filters/bugs/binding.rb +10 -10
- data/spec/filters/bugs/class.rb +8 -8
- data/spec/filters/bugs/complex.rb +2 -1
- data/spec/filters/bugs/date.rb +79 -81
- data/spec/filters/bugs/datetime.rb +29 -29
- data/spec/filters/bugs/delegate.rb +1 -3
- data/spec/filters/bugs/encoding.rb +69 -69
- data/spec/filters/bugs/enumerable.rb +22 -20
- data/spec/filters/bugs/enumerator.rb +88 -85
- data/spec/filters/bugs/exception.rb +46 -40
- data/spec/filters/bugs/file.rb +32 -32
- data/spec/filters/bugs/float.rb +26 -21
- data/spec/filters/bugs/freeze.rb +88 -0
- data/spec/filters/bugs/hash.rb +39 -38
- data/spec/filters/bugs/integer.rb +57 -44
- data/spec/filters/bugs/io.rb +1 -1
- data/spec/filters/bugs/kernel.rb +349 -269
- data/spec/filters/bugs/language.rb +220 -188
- data/spec/filters/bugs/main.rb +5 -3
- data/spec/filters/bugs/marshal.rb +38 -38
- data/spec/filters/bugs/math.rb +2 -1
- data/spec/filters/bugs/method.rb +73 -62
- data/spec/filters/bugs/module.rb +163 -143
- data/spec/filters/bugs/numeric.rb +6 -6
- data/spec/filters/bugs/objectspace.rb +16 -16
- data/spec/filters/bugs/openstruct.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +51 -51
- data/spec/filters/bugs/pathname.rb +7 -7
- data/spec/filters/bugs/proc.rb +63 -63
- data/spec/filters/bugs/random.rb +7 -6
- data/spec/filters/bugs/range.rb +12 -9
- data/spec/filters/bugs/rational.rb +8 -7
- data/spec/filters/bugs/regexp.rb +49 -48
- data/spec/filters/bugs/ruby-32.rb +56 -0
- data/spec/filters/bugs/set.rb +30 -30
- data/spec/filters/bugs/singleton.rb +4 -4
- data/spec/filters/bugs/string.rb +187 -99
- data/spec/filters/bugs/stringio.rb +7 -0
- data/spec/filters/bugs/stringscanner.rb +68 -68
- data/spec/filters/bugs/struct.rb +11 -9
- data/spec/filters/bugs/symbol.rb +1 -1
- data/spec/filters/bugs/time.rb +78 -63
- data/spec/filters/bugs/trace_point.rb +4 -4
- data/spec/filters/bugs/unboundmethod.rb +32 -17
- data/spec/filters/bugs/warnings.rb +8 -12
- data/spec/filters/unsupported/array.rb +24 -107
- data/spec/filters/unsupported/basicobject.rb +12 -12
- data/spec/filters/unsupported/bignum.rb +27 -52
- data/spec/filters/unsupported/class.rb +1 -2
- data/spec/filters/unsupported/delegator.rb +3 -3
- data/spec/filters/unsupported/enumerable.rb +2 -9
- data/spec/filters/unsupported/enumerator.rb +2 -11
- data/spec/filters/unsupported/file.rb +1 -1
- data/spec/filters/unsupported/float.rb +28 -47
- data/spec/filters/unsupported/hash.rb +8 -14
- data/spec/filters/unsupported/integer.rb +75 -91
- data/spec/filters/unsupported/kernel.rb +17 -35
- data/spec/filters/unsupported/language.rb +11 -19
- data/spec/filters/unsupported/marshal.rb +22 -41
- data/spec/filters/unsupported/matchdata.rb +28 -52
- data/spec/filters/unsupported/math.rb +1 -1
- data/spec/filters/unsupported/privacy.rb +229 -285
- data/spec/filters/unsupported/range.rb +1 -5
- data/spec/filters/unsupported/regexp.rb +40 -66
- data/spec/filters/unsupported/set.rb +2 -2
- data/spec/filters/unsupported/singleton.rb +4 -4
- data/spec/filters/unsupported/string.rb +305 -508
- data/spec/filters/unsupported/struct.rb +3 -4
- data/spec/filters/unsupported/symbol.rb +15 -18
- data/spec/filters/unsupported/thread.rb +1 -7
- data/spec/filters/unsupported/time.rb +159 -202
- data/spec/filters/unsupported/usage_of_files.rb +170 -259
- data/spec/lib/builder_spec.rb +14 -4
- data/spec/lib/rewriters/forward_args_spec.rb +32 -12
- data/spec/mspec-opal/runner.rb +2 -0
- data/spec/ruby_specs +4 -0
- data/stdlib/deno/base.rb +28 -0
- data/stdlib/deno/file.rb +340 -0
- data/stdlib/{headless_chrome.rb → headless_browser/base.rb} +1 -1
- data/stdlib/headless_browser/file.rb +15 -0
- data/stdlib/headless_browser.rb +4 -0
- data/stdlib/native.rb +1 -1
- data/stdlib/nodejs/file.rb +5 -0
- data/stdlib/opal/platform.rb +8 -6
- data/stdlib/opal-platform.rb +14 -8
- data/stdlib/set.rb +1 -258
- data/tasks/benchmarking.rake +62 -19
- data/tasks/building.rake +6 -2
- data/tasks/performance.rake +1 -1
- data/tasks/testing.rake +5 -3
- data/test/nodejs/test_file.rb +29 -10
- data/test/opal/http_server.rb +28 -11
- data/test/opal/unsupported_and_bugs.rb +2 -1
- metadata +92 -53
- data/lib/opal/cli_runners/node_modules/ultron/LICENSE +0 -22
- data/lib/opal/cli_runners/node_modules/ultron/index.js +0 -138
- data/lib/opal/cli_runners/node_modules/ultron/package.json +0 -112
- data/lib/opal/cli_runners/node_modules/ws/SECURITY.md +0 -33
- data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.fallback.js +0 -56
- data/lib/opal/cli_runners/node_modules/ws/lib/BufferUtil.js +0 -15
- data/lib/opal/cli_runners/node_modules/ws/lib/ErrorCodes.js +0 -28
- data/lib/opal/cli_runners/node_modules/ws/lib/EventTarget.js +0 -158
- data/lib/opal/cli_runners/node_modules/ws/lib/Extensions.js +0 -69
- data/lib/opal/cli_runners/node_modules/ws/lib/PerMessageDeflate.js +0 -339
- data/lib/opal/cli_runners/node_modules/ws/lib/Receiver.js +0 -520
- data/lib/opal/cli_runners/node_modules/ws/lib/Sender.js +0 -438
- data/lib/opal/cli_runners/node_modules/ws/lib/Validation.fallback.js +0 -9
- data/lib/opal/cli_runners/node_modules/ws/lib/Validation.js +0 -17
- data/lib/opal/cli_runners/node_modules/ws/lib/WebSocket.js +0 -705
- data/lib/opal/cli_runners/node_modules/ws/lib/WebSocketServer.js +0 -336
- data/spec/filters/bugs/boolean.rb +0 -3
- data/spec/filters/bugs/matrix.rb +0 -3
- data/spec/filters/unsupported/fixnum.rb +0 -15
- data/spec/filters/unsupported/freeze.rb +0 -102
- data/spec/filters/unsupported/pathname.rb +0 -4
- data/spec/filters/unsupported/proc.rb +0 -4
- data/spec/filters/unsupported/random.rb +0 -5
- data/spec/filters/unsupported/taint.rb +0 -162
@@ -1,12 +1,18 @@
|
|
1
1
|
# Commander.js
|
2
2
|
|
3
|
-
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/visionmedia/commander).
|
4
3
|
|
5
|
-
|
4
|
+
[![Build Status](https://api.travis-ci.org/tj/commander.js.svg?branch=master)](http://travis-ci.org/tj/commander.js)
|
5
|
+
[![NPM Version](http://img.shields.io/npm/v/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
|
6
|
+
[![NPM Downloads](https://img.shields.io/npm/dm/commander.svg?style=flat)](https://www.npmjs.org/package/commander)
|
7
|
+
[![Join the chat at https://gitter.im/tj/commander.js](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
8
|
+
|
9
|
+
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/commander-rb/commander).
|
10
|
+
[API documentation](http://tj.github.com/commander.js/)
|
11
|
+
|
6
12
|
|
7
13
|
## Installation
|
8
14
|
|
9
|
-
$ npm install commander
|
15
|
+
$ npm install commander --save
|
10
16
|
|
11
17
|
## Option parsing
|
12
18
|
|
@@ -22,41 +28,22 @@
|
|
22
28
|
var program = require('commander');
|
23
29
|
|
24
30
|
program
|
25
|
-
.version('0.0
|
31
|
+
.version('0.1.0')
|
26
32
|
.option('-p, --peppers', 'Add peppers')
|
27
33
|
.option('-P, --pineapple', 'Add pineapple')
|
28
|
-
.option('-b, --bbq', 'Add bbq sauce')
|
34
|
+
.option('-b, --bbq-sauce', 'Add bbq sauce')
|
29
35
|
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
|
30
36
|
.parse(process.argv);
|
31
37
|
|
32
38
|
console.log('you ordered a pizza with:');
|
33
39
|
if (program.peppers) console.log(' - peppers');
|
34
40
|
if (program.pineapple) console.log(' - pineapple');
|
35
|
-
if (program.
|
41
|
+
if (program.bbqSauce) console.log(' - bbq');
|
36
42
|
console.log(' - %s cheese', program.cheese);
|
37
43
|
```
|
38
44
|
|
39
45
|
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.
|
40
46
|
|
41
|
-
## Automated --help
|
42
|
-
|
43
|
-
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
|
44
|
-
|
45
|
-
```
|
46
|
-
$ ./examples/pizza --help
|
47
|
-
|
48
|
-
Usage: pizza [options]
|
49
|
-
|
50
|
-
Options:
|
51
|
-
|
52
|
-
-V, --version output the version number
|
53
|
-
-p, --peppers Add peppers
|
54
|
-
-P, --pineapple Add pineapple
|
55
|
-
-b, --bbq Add bbq sauce
|
56
|
-
-c, --cheese <type> Add the specified type of cheese [marble]
|
57
|
-
-h, --help output usage information
|
58
|
-
|
59
|
-
```
|
60
47
|
|
61
48
|
## Coercion
|
62
49
|
|
@@ -69,14 +56,25 @@ function list(val) {
|
|
69
56
|
return val.split(',');
|
70
57
|
}
|
71
58
|
|
59
|
+
function collect(val, memo) {
|
60
|
+
memo.push(val);
|
61
|
+
return memo;
|
62
|
+
}
|
63
|
+
|
64
|
+
function increaseVerbosity(v, total) {
|
65
|
+
return total + 1;
|
66
|
+
}
|
67
|
+
|
72
68
|
program
|
73
|
-
.version('0.0
|
69
|
+
.version('0.1.0')
|
74
70
|
.usage('[options] <file ...>')
|
75
71
|
.option('-i, --integer <n>', 'An integer argument', parseInt)
|
76
72
|
.option('-f, --float <n>', 'A float argument', parseFloat)
|
77
73
|
.option('-r, --range <a>..<b>', 'A range', range)
|
78
74
|
.option('-l, --list <items>', 'A list', list)
|
79
75
|
.option('-o, --optional [value]', 'An optional value')
|
76
|
+
.option('-c, --collect [value]', 'A repeatable value', collect, [])
|
77
|
+
.option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)
|
80
78
|
.parse(process.argv);
|
81
79
|
|
82
80
|
console.log(' int: %j', program.integer);
|
@@ -85,9 +83,131 @@ console.log(' optional: %j', program.optional);
|
|
85
83
|
program.range = program.range || [];
|
86
84
|
console.log(' range: %j..%j', program.range[0], program.range[1]);
|
87
85
|
console.log(' list: %j', program.list);
|
86
|
+
console.log(' collect: %j', program.collect);
|
87
|
+
console.log(' verbosity: %j', program.verbose);
|
88
88
|
console.log(' args: %j', program.args);
|
89
89
|
```
|
90
90
|
|
91
|
+
## Regular Expression
|
92
|
+
```js
|
93
|
+
program
|
94
|
+
.version('0.1.0')
|
95
|
+
.option('-s --size <size>', 'Pizza size', /^(large|medium|small)$/i, 'medium')
|
96
|
+
.option('-d --drink [drink]', 'Drink', /^(coke|pepsi|izze)$/i)
|
97
|
+
.parse(process.argv);
|
98
|
+
|
99
|
+
console.log(' size: %j', program.size);
|
100
|
+
console.log(' drink: %j', program.drink);
|
101
|
+
```
|
102
|
+
|
103
|
+
## Variadic arguments
|
104
|
+
|
105
|
+
The last argument of a command can be variadic, and only the last argument. To make an argument variadic you have to
|
106
|
+
append `...` to the argument name. Here is an example:
|
107
|
+
|
108
|
+
```js
|
109
|
+
#!/usr/bin/env node
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Module dependencies.
|
113
|
+
*/
|
114
|
+
|
115
|
+
var program = require('commander');
|
116
|
+
|
117
|
+
program
|
118
|
+
.version('0.1.0')
|
119
|
+
.command('rmdir <dir> [otherDirs...]')
|
120
|
+
.action(function (dir, otherDirs) {
|
121
|
+
console.log('rmdir %s', dir);
|
122
|
+
if (otherDirs) {
|
123
|
+
otherDirs.forEach(function (oDir) {
|
124
|
+
console.log('rmdir %s', oDir);
|
125
|
+
});
|
126
|
+
}
|
127
|
+
});
|
128
|
+
|
129
|
+
program.parse(process.argv);
|
130
|
+
```
|
131
|
+
|
132
|
+
An `Array` is used for the value of a variadic argument. This applies to `program.args` as well as the argument passed
|
133
|
+
to your action as demonstrated above.
|
134
|
+
|
135
|
+
## Specify the argument syntax
|
136
|
+
|
137
|
+
```js
|
138
|
+
#!/usr/bin/env node
|
139
|
+
|
140
|
+
var program = require('commander');
|
141
|
+
|
142
|
+
program
|
143
|
+
.version('0.1.0')
|
144
|
+
.arguments('<cmd> [env]')
|
145
|
+
.action(function (cmd, env) {
|
146
|
+
cmdValue = cmd;
|
147
|
+
envValue = env;
|
148
|
+
});
|
149
|
+
|
150
|
+
program.parse(process.argv);
|
151
|
+
|
152
|
+
if (typeof cmdValue === 'undefined') {
|
153
|
+
console.error('no command given!');
|
154
|
+
process.exit(1);
|
155
|
+
}
|
156
|
+
console.log('command:', cmdValue);
|
157
|
+
console.log('environment:', envValue || "no environment given");
|
158
|
+
```
|
159
|
+
Angled brackets (e.g. `<cmd>`) indicate required input. Square brackets (e.g. `[env]`) indicate optional input.
|
160
|
+
|
161
|
+
## Git-style sub-commands
|
162
|
+
|
163
|
+
```js
|
164
|
+
// file: ./examples/pm
|
165
|
+
var program = require('commander');
|
166
|
+
|
167
|
+
program
|
168
|
+
.version('0.1.0')
|
169
|
+
.command('install [name]', 'install one or more packages')
|
170
|
+
.command('search [query]', 'search with optional query')
|
171
|
+
.command('list', 'list packages installed', {isDefault: true})
|
172
|
+
.parse(process.argv);
|
173
|
+
```
|
174
|
+
|
175
|
+
When `.command()` is invoked with a description argument, no `.action(callback)` should be called to handle sub-commands, otherwise there will be an error. This tells commander that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools.
|
176
|
+
The commander will try to search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-command`, like `pm-install`, `pm-search`.
|
177
|
+
|
178
|
+
Options can be passed with the call to `.command()`. Specifying `true` for `opts.noHelp` will remove the option from the generated help output. Specifying `true` for `opts.isDefault` will run the subcommand if no other subcommand is specified.
|
179
|
+
|
180
|
+
If the program is designed to be installed globally, make sure the executables have proper modes, like `755`.
|
181
|
+
|
182
|
+
### `--harmony`
|
183
|
+
|
184
|
+
You can enable `--harmony` option in two ways:
|
185
|
+
* Use `#! /usr/bin/env node --harmony` in the sub-commands scripts. Note some os version don’t support this pattern.
|
186
|
+
* Use the `--harmony` option when call the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning sub-command process.
|
187
|
+
|
188
|
+
## Automated --help
|
189
|
+
|
190
|
+
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
|
191
|
+
|
192
|
+
```
|
193
|
+
$ ./examples/pizza --help
|
194
|
+
|
195
|
+
Usage: pizza [options]
|
196
|
+
|
197
|
+
An application for pizzas ordering
|
198
|
+
|
199
|
+
Options:
|
200
|
+
|
201
|
+
-h, --help output usage information
|
202
|
+
-V, --version output the version number
|
203
|
+
-p, --peppers Add peppers
|
204
|
+
-P, --pineapple Add pineapple
|
205
|
+
-b, --bbq Add bbq sauce
|
206
|
+
-c, --cheese <type> Add the specified type of cheese [marble]
|
207
|
+
-C, --no-cheese You do not want any cheese
|
208
|
+
|
209
|
+
```
|
210
|
+
|
91
211
|
## Custom help
|
92
212
|
|
93
213
|
You can display arbitrary `-h, --help` information
|
@@ -104,14 +224,10 @@ console.log(' args: %j', program.args);
|
|
104
224
|
* Module dependencies.
|
105
225
|
*/
|
106
226
|
|
107
|
-
var program = require('
|
108
|
-
|
109
|
-
function list(val) {
|
110
|
-
return val.split(',').map(Number);
|
111
|
-
}
|
227
|
+
var program = require('commander');
|
112
228
|
|
113
229
|
program
|
114
|
-
.version('0.0
|
230
|
+
.version('0.1.0')
|
115
231
|
.option('-f, --foo', 'enable some foo')
|
116
232
|
.option('-b, --bar', 'enable some bar')
|
117
233
|
.option('-B, --baz', 'enable some baz');
|
@@ -132,7 +248,7 @@ program.parse(process.argv);
|
|
132
248
|
console.log('stuff');
|
133
249
|
```
|
134
250
|
|
135
|
-
|
251
|
+
Yields the following help output when `node script-name.js -h` or `node script-name.js --help` are run:
|
136
252
|
|
137
253
|
```
|
138
254
|
|
@@ -153,43 +269,83 @@ Examples:
|
|
153
269
|
|
154
270
|
```
|
155
271
|
|
156
|
-
## .outputHelp()
|
272
|
+
## .outputHelp(cb)
|
157
273
|
|
158
|
-
|
274
|
+
Output help information without exiting.
|
275
|
+
Optional callback cb allows post-processing of help text before it is displayed.
|
276
|
+
|
277
|
+
If you want to display help by default (e.g. if no command was provided), you can use something like:
|
278
|
+
|
279
|
+
```js
|
280
|
+
var program = require('commander');
|
281
|
+
var colors = require('colors');
|
282
|
+
|
283
|
+
program
|
284
|
+
.version('0.1.0')
|
285
|
+
.command('getstream [url]', 'get stream URL')
|
286
|
+
.parse(process.argv);
|
159
287
|
|
160
|
-
|
288
|
+
if (!process.argv.slice(2).length) {
|
289
|
+
program.outputHelp(make_red);
|
290
|
+
}
|
291
|
+
|
292
|
+
function make_red(txt) {
|
293
|
+
return colors.red(txt); //display the help text in red on the console
|
294
|
+
}
|
295
|
+
```
|
296
|
+
|
297
|
+
## .help(cb)
|
161
298
|
|
162
299
|
Output help information and exit immediately.
|
300
|
+
Optional callback cb allows post-processing of help text before it is displayed.
|
301
|
+
|
302
|
+
## Examples
|
303
|
+
|
304
|
+
```js
|
305
|
+
var program = require('commander');
|
163
306
|
|
164
|
-
|
307
|
+
program
|
308
|
+
.version('0.1.0')
|
309
|
+
.option('-C, --chdir <path>', 'change the working directory')
|
310
|
+
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
311
|
+
.option('-T, --no-tests', 'ignore test hook');
|
165
312
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
313
|
+
program
|
314
|
+
.command('setup [env]')
|
315
|
+
.description('run setup commands for all envs')
|
316
|
+
.option("-s, --setup_mode [mode]", "Which setup mode to use")
|
317
|
+
.action(function(env, options){
|
318
|
+
var mode = options.setup_mode || "normal";
|
319
|
+
env = env || 'all';
|
320
|
+
console.log('setup for %s env(s) with %s mode', env, mode);
|
321
|
+
});
|
171
322
|
|
172
|
-
|
323
|
+
program
|
324
|
+
.command('exec <cmd>')
|
325
|
+
.alias('ex')
|
326
|
+
.description('execute the given remote cmd')
|
327
|
+
.option("-e, --exec_mode <mode>", "Which exec mode to use")
|
328
|
+
.action(function(cmd, options){
|
329
|
+
console.log('exec "%s" using %s mode', cmd, options.exec_mode);
|
330
|
+
}).on('--help', function() {
|
331
|
+
console.log(' Examples:');
|
332
|
+
console.log();
|
333
|
+
console.log(' $ deploy exec sequential');
|
334
|
+
console.log(' $ deploy exec async');
|
335
|
+
console.log();
|
336
|
+
});
|
173
337
|
|
174
|
-
|
338
|
+
program
|
339
|
+
.command('*')
|
340
|
+
.action(function(env){
|
341
|
+
console.log('deploying "%s"', env);
|
342
|
+
});
|
175
343
|
|
176
|
-
|
344
|
+
program.parse(process.argv);
|
345
|
+
```
|
177
346
|
|
178
|
-
|
179
|
-
a copy of this software and associated documentation files (the
|
180
|
-
'Software'), to deal in the Software without restriction, including
|
181
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
182
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
183
|
-
permit persons to whom the Software is furnished to do so, subject to
|
184
|
-
the following conditions:
|
347
|
+
More Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.
|
185
348
|
|
186
|
-
|
187
|
-
included in all copies or substantial portions of the Software.
|
349
|
+
## License
|
188
350
|
|
189
|
-
|
190
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
191
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
192
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
193
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
194
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
195
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
351
|
+
MIT
|