dragonfly_chrome_headless 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dragonfly_chrome_headless.gemspec +27 -0
- data/lib/dragonfly_chrome_headless.rb +9 -0
- data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
- data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
- data/lib/dragonfly_chrome_headless/version.rb +3 -0
- data/node_modules/.bin/chrome-remote-interface +1 -0
- data/node_modules/.bin/mkdirp +1 -0
- data/node_modules/.bin/rimraf +1 -0
- data/node_modules/@types/core-js/LICENSE +21 -0
- data/node_modules/@types/core-js/README.md +16 -0
- data/node_modules/@types/core-js/index.d.ts +2452 -0
- data/node_modules/@types/core-js/package.json +85 -0
- data/node_modules/@types/mkdirp/README.md +18 -0
- data/node_modules/@types/mkdirp/index.d.ts +14 -0
- data/node_modules/@types/mkdirp/package.json +77 -0
- data/node_modules/@types/mkdirp/types-metadata.json +25 -0
- data/node_modules/@types/node/README.md +16 -0
- data/node_modules/@types/node/index.d.ts +4132 -0
- data/node_modules/@types/node/package.json +84 -0
- data/node_modules/balanced-match/.npmignore +5 -0
- data/node_modules/balanced-match/LICENSE.md +21 -0
- data/node_modules/balanced-match/README.md +91 -0
- data/node_modules/balanced-match/index.js +59 -0
- data/node_modules/balanced-match/package.json +112 -0
- data/node_modules/brace-expansion/README.md +123 -0
- data/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/brace-expansion/package.json +114 -0
- data/node_modules/chrome-launcher/.clang-format +6 -0
- data/node_modules/chrome-launcher/.npmignore +11 -0
- data/node_modules/chrome-launcher/README.md +123 -0
- data/node_modules/chrome-launcher/ask.js +32 -0
- data/node_modules/chrome-launcher/ask.ts +35 -0
- data/node_modules/chrome-launcher/chrome-finder.js +157 -0
- data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
- data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
- data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
- data/node_modules/chrome-launcher/compiled-check.js +14 -0
- data/node_modules/chrome-launcher/flags.js +27 -0
- data/node_modules/chrome-launcher/flags.ts +26 -0
- data/node_modules/chrome-launcher/index.js +7 -0
- data/node_modules/chrome-launcher/index.ts +1 -0
- data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
- data/node_modules/chrome-launcher/package.json +116 -0
- data/node_modules/chrome-launcher/random-port.js +24 -0
- data/node_modules/chrome-launcher/random-port.ts +23 -0
- data/node_modules/chrome-launcher/tsconfig.json +19 -0
- data/node_modules/chrome-launcher/utils.js +52 -0
- data/node_modules/chrome-launcher/utils.ts +44 -0
- data/node_modules/chrome-launcher/yarn.lock +1486 -0
- data/node_modules/chrome-remote-interface/LICENSE +18 -0
- data/node_modules/chrome-remote-interface/README.md +849 -0
- data/node_modules/chrome-remote-interface/bin/client.js +337 -0
- data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
- data/node_modules/chrome-remote-interface/index.js +39 -0
- data/node_modules/chrome-remote-interface/lib/api.js +84 -0
- data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
- data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
- data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
- data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
- data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
- data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
- data/node_modules/chrome-remote-interface/package.json +128 -0
- data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
- data/node_modules/commander/Readme.md +195 -0
- data/node_modules/commander/index.js +851 -0
- data/node_modules/commander/package.json +92 -0
- data/node_modules/concat-map/.travis.yml +4 -0
- data/node_modules/concat-map/LICENSE +18 -0
- data/node_modules/concat-map/README.markdown +62 -0
- data/node_modules/concat-map/example/map.js +6 -0
- data/node_modules/concat-map/index.js +13 -0
- data/node_modules/concat-map/package.json +117 -0
- data/node_modules/concat-map/test/map.js +39 -0
- data/node_modules/debug/.coveralls.yml +1 -0
- data/node_modules/debug/.eslintrc +11 -0
- data/node_modules/debug/.npmignore +9 -0
- data/node_modules/debug/.travis.yml +14 -0
- data/node_modules/debug/CHANGELOG.md +357 -0
- data/node_modules/debug/LICENSE +19 -0
- data/node_modules/debug/Makefile +50 -0
- data/node_modules/debug/Readme.md +312 -0
- data/node_modules/debug/component.json +19 -0
- data/node_modules/debug/karma.conf.js +70 -0
- data/node_modules/debug/node.js +1 -0
- data/node_modules/debug/package.json +124 -0
- data/node_modules/debug/src/browser.js +185 -0
- data/node_modules/debug/src/debug.js +202 -0
- data/node_modules/debug/src/index.js +10 -0
- data/node_modules/debug/src/node.js +246 -0
- data/node_modules/fs.realpath/LICENSE +43 -0
- data/node_modules/fs.realpath/README.md +33 -0
- data/node_modules/fs.realpath/index.js +66 -0
- data/node_modules/fs.realpath/old.js +303 -0
- data/node_modules/fs.realpath/package.json +94 -0
- data/node_modules/glob/LICENSE +15 -0
- data/node_modules/glob/README.md +368 -0
- data/node_modules/glob/changelog.md +67 -0
- data/node_modules/glob/common.js +240 -0
- data/node_modules/glob/glob.js +790 -0
- data/node_modules/glob/package.json +112 -0
- data/node_modules/glob/sync.js +486 -0
- data/node_modules/html-pdf-chrome/.npmignore +9 -0
- data/node_modules/html-pdf-chrome/LICENSE +21 -0
- data/node_modules/html-pdf-chrome/README.md +165 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
- data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
- data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
- data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
- data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
- data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
- data/node_modules/html-pdf-chrome/package.json +133 -0
- data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
- data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
- data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
- data/node_modules/html-pdf-chrome/src/index.ts +179 -0
- data/node_modules/inflight/LICENSE +15 -0
- data/node_modules/inflight/README.md +37 -0
- data/node_modules/inflight/inflight.js +54 -0
- data/node_modules/inflight/package.json +105 -0
- data/node_modules/inherits/LICENSE +16 -0
- data/node_modules/inherits/README.md +42 -0
- data/node_modules/inherits/inherits.js +7 -0
- data/node_modules/inherits/inherits_browser.js +23 -0
- data/node_modules/inherits/package.json +97 -0
- data/node_modules/lighthouse-logger/README.md +4 -0
- data/node_modules/lighthouse-logger/index.js +212 -0
- data/node_modules/lighthouse-logger/package.json +69 -0
- data/node_modules/lighthouse-logger/yarn.lock +13 -0
- data/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/minimatch/README.md +209 -0
- data/node_modules/minimatch/minimatch.js +923 -0
- data/node_modules/minimatch/package.json +99 -0
- data/node_modules/minimist/.travis.yml +4 -0
- data/node_modules/minimist/LICENSE +18 -0
- data/node_modules/minimist/example/parse.js +2 -0
- data/node_modules/minimist/index.js +187 -0
- data/node_modules/minimist/package.json +101 -0
- data/node_modules/minimist/readme.markdown +73 -0
- data/node_modules/minimist/test/dash.js +24 -0
- data/node_modules/minimist/test/default_bool.js +20 -0
- data/node_modules/minimist/test/dotted.js +16 -0
- data/node_modules/minimist/test/long.js +31 -0
- data/node_modules/minimist/test/parse.js +318 -0
- data/node_modules/minimist/test/parse_modified.js +9 -0
- data/node_modules/minimist/test/short.js +67 -0
- data/node_modules/minimist/test/whitespace.js +8 -0
- data/node_modules/mkdirp/.travis.yml +8 -0
- data/node_modules/mkdirp/LICENSE +21 -0
- data/node_modules/mkdirp/bin/cmd.js +33 -0
- data/node_modules/mkdirp/bin/usage.txt +12 -0
- data/node_modules/mkdirp/examples/pow.js +6 -0
- data/node_modules/mkdirp/index.js +98 -0
- data/node_modules/mkdirp/package.json +93 -0
- data/node_modules/mkdirp/readme.markdown +100 -0
- data/node_modules/mkdirp/test/chmod.js +41 -0
- data/node_modules/mkdirp/test/clobber.js +38 -0
- data/node_modules/mkdirp/test/mkdirp.js +28 -0
- data/node_modules/mkdirp/test/opts_fs.js +29 -0
- data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
- data/node_modules/mkdirp/test/perm.js +32 -0
- data/node_modules/mkdirp/test/perm_sync.js +36 -0
- data/node_modules/mkdirp/test/race.js +37 -0
- data/node_modules/mkdirp/test/rel.js +32 -0
- data/node_modules/mkdirp/test/return.js +25 -0
- data/node_modules/mkdirp/test/return_sync.js +24 -0
- data/node_modules/mkdirp/test/root.js +19 -0
- data/node_modules/mkdirp/test/sync.js +32 -0
- data/node_modules/mkdirp/test/umask.js +28 -0
- data/node_modules/mkdirp/test/umask_sync.js +32 -0
- data/node_modules/ms/README.md +51 -0
- data/node_modules/ms/index.js +152 -0
- data/node_modules/ms/license.md +21 -0
- data/node_modules/ms/package.json +109 -0
- data/node_modules/once/LICENSE +15 -0
- data/node_modules/once/README.md +79 -0
- data/node_modules/once/once.js +42 -0
- data/node_modules/once/package.json +101 -0
- data/node_modules/path-is-absolute/index.js +20 -0
- data/node_modules/path-is-absolute/license +21 -0
- data/node_modules/path-is-absolute/package.json +111 -0
- data/node_modules/path-is-absolute/readme.md +59 -0
- data/node_modules/rimraf/LICENSE +15 -0
- data/node_modules/rimraf/README.md +101 -0
- data/node_modules/rimraf/bin.js +50 -0
- data/node_modules/rimraf/package.json +99 -0
- data/node_modules/rimraf/rimraf.js +363 -0
- data/node_modules/ultron/LICENSE +22 -0
- data/node_modules/ultron/index.js +138 -0
- data/node_modules/ultron/package.json +112 -0
- data/node_modules/wrappy/LICENSE +15 -0
- data/node_modules/wrappy/README.md +36 -0
- data/node_modules/wrappy/package.json +97 -0
- data/node_modules/wrappy/wrappy.js +33 -0
- data/node_modules/ws/LICENSE +21 -0
- data/node_modules/ws/README.md +259 -0
- data/node_modules/ws/SECURITY.md +33 -0
- data/node_modules/ws/index.js +15 -0
- data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
- data/node_modules/ws/lib/BufferUtil.js +15 -0
- data/node_modules/ws/lib/ErrorCodes.js +28 -0
- data/node_modules/ws/lib/EventTarget.js +158 -0
- data/node_modules/ws/lib/Extensions.js +69 -0
- data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
- data/node_modules/ws/lib/Receiver.js +520 -0
- data/node_modules/ws/lib/Sender.js +438 -0
- data/node_modules/ws/lib/Validation.fallback.js +9 -0
- data/node_modules/ws/lib/Validation.js +17 -0
- data/node_modules/ws/lib/WebSocket.js +705 -0
- data/node_modules/ws/lib/WebSocketServer.js +336 -0
- data/node_modules/ws/package.json +122 -0
- data/package.json +26 -0
- data/samples/sample.html +13 -0
- data/script/rasterize.js +18 -0
- metadata +325 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
var parse = require('../');
|
2
|
+
var test = require('tape');
|
3
|
+
|
4
|
+
test('-', function (t) {
|
5
|
+
t.plan(5);
|
6
|
+
t.deepEqual(parse([ '-n', '-' ]), { n: '-', _: [] });
|
7
|
+
t.deepEqual(parse([ '-' ]), { _: [ '-' ] });
|
8
|
+
t.deepEqual(parse([ '-f-' ]), { f: '-', _: [] });
|
9
|
+
t.deepEqual(
|
10
|
+
parse([ '-b', '-' ], { boolean: 'b' }),
|
11
|
+
{ b: true, _: [ '-' ] }
|
12
|
+
);
|
13
|
+
t.deepEqual(
|
14
|
+
parse([ '-s', '-' ], { string: 's' }),
|
15
|
+
{ s: '-', _: [] }
|
16
|
+
);
|
17
|
+
});
|
18
|
+
|
19
|
+
test('-a -- b', function (t) {
|
20
|
+
t.plan(3);
|
21
|
+
t.deepEqual(parse([ '-a', '--', 'b' ]), { a: true, _: [ 'b' ] });
|
22
|
+
t.deepEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
|
23
|
+
t.deepEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
|
24
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
var test = require('tape');
|
2
|
+
var parse = require('../');
|
3
|
+
|
4
|
+
test('boolean default true', function (t) {
|
5
|
+
var argv = parse([], {
|
6
|
+
boolean: 'sometrue',
|
7
|
+
default: { sometrue: true }
|
8
|
+
});
|
9
|
+
t.equal(argv.sometrue, true);
|
10
|
+
t.end();
|
11
|
+
});
|
12
|
+
|
13
|
+
test('boolean default false', function (t) {
|
14
|
+
var argv = parse([], {
|
15
|
+
boolean: 'somefalse',
|
16
|
+
default: { somefalse: false }
|
17
|
+
});
|
18
|
+
t.equal(argv.somefalse, false);
|
19
|
+
t.end();
|
20
|
+
});
|
@@ -0,0 +1,16 @@
|
|
1
|
+
var parse = require('../');
|
2
|
+
var test = require('tape');
|
3
|
+
|
4
|
+
test('dotted alias', function (t) {
|
5
|
+
var argv = parse(['--a.b', '22'], {default: {'a.b': 11}, alias: {'a.b': 'aa.bb'}});
|
6
|
+
t.equal(argv.a.b, 22);
|
7
|
+
t.equal(argv.aa.bb, 22);
|
8
|
+
t.end();
|
9
|
+
});
|
10
|
+
|
11
|
+
test('dotted default', function (t) {
|
12
|
+
var argv = parse('', {default: {'a.b': 11}, alias: {'a.b': 'aa.bb'}});
|
13
|
+
t.equal(argv.a.b, 11);
|
14
|
+
t.equal(argv.aa.bb, 11);
|
15
|
+
t.end();
|
16
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
var test = require('tape');
|
2
|
+
var parse = require('../');
|
3
|
+
|
4
|
+
test('long opts', function (t) {
|
5
|
+
t.deepEqual(
|
6
|
+
parse([ '--bool' ]),
|
7
|
+
{ bool : true, _ : [] },
|
8
|
+
'long boolean'
|
9
|
+
);
|
10
|
+
t.deepEqual(
|
11
|
+
parse([ '--pow', 'xixxle' ]),
|
12
|
+
{ pow : 'xixxle', _ : [] },
|
13
|
+
'long capture sp'
|
14
|
+
);
|
15
|
+
t.deepEqual(
|
16
|
+
parse([ '--pow=xixxle' ]),
|
17
|
+
{ pow : 'xixxle', _ : [] },
|
18
|
+
'long capture eq'
|
19
|
+
);
|
20
|
+
t.deepEqual(
|
21
|
+
parse([ '--host', 'localhost', '--port', '555' ]),
|
22
|
+
{ host : 'localhost', port : 555, _ : [] },
|
23
|
+
'long captures sp'
|
24
|
+
);
|
25
|
+
t.deepEqual(
|
26
|
+
parse([ '--host=localhost', '--port=555' ]),
|
27
|
+
{ host : 'localhost', port : 555, _ : [] },
|
28
|
+
'long captures eq'
|
29
|
+
);
|
30
|
+
t.end();
|
31
|
+
});
|
@@ -0,0 +1,318 @@
|
|
1
|
+
var parse = require('../');
|
2
|
+
var test = require('tape');
|
3
|
+
|
4
|
+
test('parse args', function (t) {
|
5
|
+
t.deepEqual(
|
6
|
+
parse([ '--no-moo' ]),
|
7
|
+
{ moo : false, _ : [] },
|
8
|
+
'no'
|
9
|
+
);
|
10
|
+
t.deepEqual(
|
11
|
+
parse([ '-v', 'a', '-v', 'b', '-v', 'c' ]),
|
12
|
+
{ v : ['a','b','c'], _ : [] },
|
13
|
+
'multi'
|
14
|
+
);
|
15
|
+
t.end();
|
16
|
+
});
|
17
|
+
|
18
|
+
test('comprehensive', function (t) {
|
19
|
+
t.deepEqual(
|
20
|
+
parse([
|
21
|
+
'--name=meowmers', 'bare', '-cats', 'woo',
|
22
|
+
'-h', 'awesome', '--multi=quux',
|
23
|
+
'--key', 'value',
|
24
|
+
'-b', '--bool', '--no-meep', '--multi=baz',
|
25
|
+
'--', '--not-a-flag', 'eek'
|
26
|
+
]),
|
27
|
+
{
|
28
|
+
c : true,
|
29
|
+
a : true,
|
30
|
+
t : true,
|
31
|
+
s : 'woo',
|
32
|
+
h : 'awesome',
|
33
|
+
b : true,
|
34
|
+
bool : true,
|
35
|
+
key : 'value',
|
36
|
+
multi : [ 'quux', 'baz' ],
|
37
|
+
meep : false,
|
38
|
+
name : 'meowmers',
|
39
|
+
_ : [ 'bare', '--not-a-flag', 'eek' ]
|
40
|
+
}
|
41
|
+
);
|
42
|
+
t.end();
|
43
|
+
});
|
44
|
+
|
45
|
+
test('nums', function (t) {
|
46
|
+
var argv = parse([
|
47
|
+
'-x', '1234',
|
48
|
+
'-y', '5.67',
|
49
|
+
'-z', '1e7',
|
50
|
+
'-w', '10f',
|
51
|
+
'--hex', '0xdeadbeef',
|
52
|
+
'789'
|
53
|
+
]);
|
54
|
+
t.deepEqual(argv, {
|
55
|
+
x : 1234,
|
56
|
+
y : 5.67,
|
57
|
+
z : 1e7,
|
58
|
+
w : '10f',
|
59
|
+
hex : 0xdeadbeef,
|
60
|
+
_ : [ 789 ]
|
61
|
+
});
|
62
|
+
t.deepEqual(typeof argv.x, 'number');
|
63
|
+
t.deepEqual(typeof argv.y, 'number');
|
64
|
+
t.deepEqual(typeof argv.z, 'number');
|
65
|
+
t.deepEqual(typeof argv.w, 'string');
|
66
|
+
t.deepEqual(typeof argv.hex, 'number');
|
67
|
+
t.deepEqual(typeof argv._[0], 'number');
|
68
|
+
t.end();
|
69
|
+
});
|
70
|
+
|
71
|
+
test('flag boolean', function (t) {
|
72
|
+
var argv = parse([ '-t', 'moo' ], { boolean: 't' });
|
73
|
+
t.deepEqual(argv, { t : true, _ : [ 'moo' ] });
|
74
|
+
t.deepEqual(typeof argv.t, 'boolean');
|
75
|
+
t.end();
|
76
|
+
});
|
77
|
+
|
78
|
+
test('flag boolean value', function (t) {
|
79
|
+
var argv = parse(['--verbose', 'false', 'moo', '-t', 'true'], {
|
80
|
+
boolean: [ 't', 'verbose' ],
|
81
|
+
default: { verbose: true }
|
82
|
+
});
|
83
|
+
|
84
|
+
t.deepEqual(argv, {
|
85
|
+
verbose: false,
|
86
|
+
t: true,
|
87
|
+
_: ['moo']
|
88
|
+
});
|
89
|
+
|
90
|
+
t.deepEqual(typeof argv.verbose, 'boolean');
|
91
|
+
t.deepEqual(typeof argv.t, 'boolean');
|
92
|
+
t.end();
|
93
|
+
});
|
94
|
+
|
95
|
+
test('flag boolean default false', function (t) {
|
96
|
+
var argv = parse(['moo'], {
|
97
|
+
boolean: ['t', 'verbose'],
|
98
|
+
default: { verbose: false, t: false }
|
99
|
+
});
|
100
|
+
|
101
|
+
t.deepEqual(argv, {
|
102
|
+
verbose: false,
|
103
|
+
t: false,
|
104
|
+
_: ['moo']
|
105
|
+
});
|
106
|
+
|
107
|
+
t.deepEqual(typeof argv.verbose, 'boolean');
|
108
|
+
t.deepEqual(typeof argv.t, 'boolean');
|
109
|
+
t.end();
|
110
|
+
|
111
|
+
});
|
112
|
+
|
113
|
+
test('boolean groups', function (t) {
|
114
|
+
var argv = parse([ '-x', '-z', 'one', 'two', 'three' ], {
|
115
|
+
boolean: ['x','y','z']
|
116
|
+
});
|
117
|
+
|
118
|
+
t.deepEqual(argv, {
|
119
|
+
x : true,
|
120
|
+
y : false,
|
121
|
+
z : true,
|
122
|
+
_ : [ 'one', 'two', 'three' ]
|
123
|
+
});
|
124
|
+
|
125
|
+
t.deepEqual(typeof argv.x, 'boolean');
|
126
|
+
t.deepEqual(typeof argv.y, 'boolean');
|
127
|
+
t.deepEqual(typeof argv.z, 'boolean');
|
128
|
+
t.end();
|
129
|
+
});
|
130
|
+
|
131
|
+
test('newlines in params' , function (t) {
|
132
|
+
var args = parse([ '-s', "X\nX" ])
|
133
|
+
t.deepEqual(args, { _ : [], s : "X\nX" });
|
134
|
+
|
135
|
+
// reproduce in bash:
|
136
|
+
// VALUE="new
|
137
|
+
// line"
|
138
|
+
// node program.js --s="$VALUE"
|
139
|
+
args = parse([ "--s=X\nX" ])
|
140
|
+
t.deepEqual(args, { _ : [], s : "X\nX" });
|
141
|
+
t.end();
|
142
|
+
});
|
143
|
+
|
144
|
+
test('strings' , function (t) {
|
145
|
+
var s = parse([ '-s', '0001234' ], { string: 's' }).s;
|
146
|
+
t.equal(s, '0001234');
|
147
|
+
t.equal(typeof s, 'string');
|
148
|
+
|
149
|
+
var x = parse([ '-x', '56' ], { string: 'x' }).x;
|
150
|
+
t.equal(x, '56');
|
151
|
+
t.equal(typeof x, 'string');
|
152
|
+
t.end();
|
153
|
+
});
|
154
|
+
|
155
|
+
test('stringArgs', function (t) {
|
156
|
+
var s = parse([ ' ', ' ' ], { string: '_' })._;
|
157
|
+
t.same(s.length, 2);
|
158
|
+
t.same(typeof s[0], 'string');
|
159
|
+
t.same(s[0], ' ');
|
160
|
+
t.same(typeof s[1], 'string');
|
161
|
+
t.same(s[1], ' ');
|
162
|
+
t.end();
|
163
|
+
});
|
164
|
+
|
165
|
+
test('empty strings', function(t) {
|
166
|
+
var s = parse([ '-s' ], { string: 's' }).s;
|
167
|
+
t.equal(s, '');
|
168
|
+
t.equal(typeof s, 'string');
|
169
|
+
|
170
|
+
var str = parse([ '--str' ], { string: 'str' }).str;
|
171
|
+
t.equal(str, '');
|
172
|
+
t.equal(typeof str, 'string');
|
173
|
+
|
174
|
+
var letters = parse([ '-art' ], {
|
175
|
+
string: [ 'a', 't' ]
|
176
|
+
});
|
177
|
+
|
178
|
+
t.equal(letters.a, '');
|
179
|
+
t.equal(letters.r, true);
|
180
|
+
t.equal(letters.t, '');
|
181
|
+
|
182
|
+
t.end();
|
183
|
+
});
|
184
|
+
|
185
|
+
|
186
|
+
test('slashBreak', function (t) {
|
187
|
+
t.same(
|
188
|
+
parse([ '-I/foo/bar/baz' ]),
|
189
|
+
{ I : '/foo/bar/baz', _ : [] }
|
190
|
+
);
|
191
|
+
t.same(
|
192
|
+
parse([ '-xyz/foo/bar/baz' ]),
|
193
|
+
{ x : true, y : true, z : '/foo/bar/baz', _ : [] }
|
194
|
+
);
|
195
|
+
t.end();
|
196
|
+
});
|
197
|
+
|
198
|
+
test('alias', function (t) {
|
199
|
+
var argv = parse([ '-f', '11', '--zoom', '55' ], {
|
200
|
+
alias: { z: 'zoom' }
|
201
|
+
});
|
202
|
+
t.equal(argv.zoom, 55);
|
203
|
+
t.equal(argv.z, argv.zoom);
|
204
|
+
t.equal(argv.f, 11);
|
205
|
+
t.end();
|
206
|
+
});
|
207
|
+
|
208
|
+
test('multiAlias', function (t) {
|
209
|
+
var argv = parse([ '-f', '11', '--zoom', '55' ], {
|
210
|
+
alias: { z: [ 'zm', 'zoom' ] }
|
211
|
+
});
|
212
|
+
t.equal(argv.zoom, 55);
|
213
|
+
t.equal(argv.z, argv.zoom);
|
214
|
+
t.equal(argv.z, argv.zm);
|
215
|
+
t.equal(argv.f, 11);
|
216
|
+
t.end();
|
217
|
+
});
|
218
|
+
|
219
|
+
test('nested dotted objects', function (t) {
|
220
|
+
var argv = parse([
|
221
|
+
'--foo.bar', '3', '--foo.baz', '4',
|
222
|
+
'--foo.quux.quibble', '5', '--foo.quux.o_O',
|
223
|
+
'--beep.boop'
|
224
|
+
]);
|
225
|
+
|
226
|
+
t.same(argv.foo, {
|
227
|
+
bar : 3,
|
228
|
+
baz : 4,
|
229
|
+
quux : {
|
230
|
+
quibble : 5,
|
231
|
+
o_O : true
|
232
|
+
}
|
233
|
+
});
|
234
|
+
t.same(argv.beep, { boop : true });
|
235
|
+
t.end();
|
236
|
+
});
|
237
|
+
|
238
|
+
test('boolean and alias with chainable api', function (t) {
|
239
|
+
var aliased = [ '-h', 'derp' ];
|
240
|
+
var regular = [ '--herp', 'derp' ];
|
241
|
+
var opts = {
|
242
|
+
herp: { alias: 'h', boolean: true }
|
243
|
+
};
|
244
|
+
var aliasedArgv = parse(aliased, {
|
245
|
+
boolean: 'herp',
|
246
|
+
alias: { h: 'herp' }
|
247
|
+
});
|
248
|
+
var propertyArgv = parse(regular, {
|
249
|
+
boolean: 'herp',
|
250
|
+
alias: { h: 'herp' }
|
251
|
+
});
|
252
|
+
var expected = {
|
253
|
+
herp: true,
|
254
|
+
h: true,
|
255
|
+
'_': [ 'derp' ]
|
256
|
+
};
|
257
|
+
|
258
|
+
t.same(aliasedArgv, expected);
|
259
|
+
t.same(propertyArgv, expected);
|
260
|
+
t.end();
|
261
|
+
});
|
262
|
+
|
263
|
+
test('boolean and alias with options hash', function (t) {
|
264
|
+
var aliased = [ '-h', 'derp' ];
|
265
|
+
var regular = [ '--herp', 'derp' ];
|
266
|
+
var opts = {
|
267
|
+
alias: { 'h': 'herp' },
|
268
|
+
boolean: 'herp'
|
269
|
+
};
|
270
|
+
var aliasedArgv = parse(aliased, opts);
|
271
|
+
var propertyArgv = parse(regular, opts);
|
272
|
+
var expected = {
|
273
|
+
herp: true,
|
274
|
+
h: true,
|
275
|
+
'_': [ 'derp' ]
|
276
|
+
};
|
277
|
+
t.same(aliasedArgv, expected);
|
278
|
+
t.same(propertyArgv, expected);
|
279
|
+
t.end();
|
280
|
+
});
|
281
|
+
|
282
|
+
test('boolean and alias using explicit true', function (t) {
|
283
|
+
var aliased = [ '-h', 'true' ];
|
284
|
+
var regular = [ '--herp', 'true' ];
|
285
|
+
var opts = {
|
286
|
+
alias: { h: 'herp' },
|
287
|
+
boolean: 'h'
|
288
|
+
};
|
289
|
+
var aliasedArgv = parse(aliased, opts);
|
290
|
+
var propertyArgv = parse(regular, opts);
|
291
|
+
var expected = {
|
292
|
+
herp: true,
|
293
|
+
h: true,
|
294
|
+
'_': [ ]
|
295
|
+
};
|
296
|
+
|
297
|
+
t.same(aliasedArgv, expected);
|
298
|
+
t.same(propertyArgv, expected);
|
299
|
+
t.end();
|
300
|
+
});
|
301
|
+
|
302
|
+
// regression, see https://github.com/substack/node-optimist/issues/71
|
303
|
+
test('boolean and --x=true', function(t) {
|
304
|
+
var parsed = parse(['--boool', '--other=true'], {
|
305
|
+
boolean: 'boool'
|
306
|
+
});
|
307
|
+
|
308
|
+
t.same(parsed.boool, true);
|
309
|
+
t.same(parsed.other, 'true');
|
310
|
+
|
311
|
+
parsed = parse(['--boool', '--other=false'], {
|
312
|
+
boolean: 'boool'
|
313
|
+
});
|
314
|
+
|
315
|
+
t.same(parsed.boool, true);
|
316
|
+
t.same(parsed.other, 'false');
|
317
|
+
t.end();
|
318
|
+
});
|
@@ -0,0 +1,67 @@
|
|
1
|
+
var parse = require('../');
|
2
|
+
var test = require('tape');
|
3
|
+
|
4
|
+
test('numeric short args', function (t) {
|
5
|
+
t.plan(2);
|
6
|
+
t.deepEqual(parse([ '-n123' ]), { n: 123, _: [] });
|
7
|
+
t.deepEqual(
|
8
|
+
parse([ '-123', '456' ]),
|
9
|
+
{ 1: true, 2: true, 3: 456, _: [] }
|
10
|
+
);
|
11
|
+
});
|
12
|
+
|
13
|
+
test('short', function (t) {
|
14
|
+
t.deepEqual(
|
15
|
+
parse([ '-b' ]),
|
16
|
+
{ b : true, _ : [] },
|
17
|
+
'short boolean'
|
18
|
+
);
|
19
|
+
t.deepEqual(
|
20
|
+
parse([ 'foo', 'bar', 'baz' ]),
|
21
|
+
{ _ : [ 'foo', 'bar', 'baz' ] },
|
22
|
+
'bare'
|
23
|
+
);
|
24
|
+
t.deepEqual(
|
25
|
+
parse([ '-cats' ]),
|
26
|
+
{ c : true, a : true, t : true, s : true, _ : [] },
|
27
|
+
'group'
|
28
|
+
);
|
29
|
+
t.deepEqual(
|
30
|
+
parse([ '-cats', 'meow' ]),
|
31
|
+
{ c : true, a : true, t : true, s : 'meow', _ : [] },
|
32
|
+
'short group next'
|
33
|
+
);
|
34
|
+
t.deepEqual(
|
35
|
+
parse([ '-h', 'localhost' ]),
|
36
|
+
{ h : 'localhost', _ : [] },
|
37
|
+
'short capture'
|
38
|
+
);
|
39
|
+
t.deepEqual(
|
40
|
+
parse([ '-h', 'localhost', '-p', '555' ]),
|
41
|
+
{ h : 'localhost', p : 555, _ : [] },
|
42
|
+
'short captures'
|
43
|
+
);
|
44
|
+
t.end();
|
45
|
+
});
|
46
|
+
|
47
|
+
test('mixed short bool and capture', function (t) {
|
48
|
+
t.same(
|
49
|
+
parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
|
50
|
+
{
|
51
|
+
f : true, p : 555, h : 'localhost',
|
52
|
+
_ : [ 'script.js' ]
|
53
|
+
}
|
54
|
+
);
|
55
|
+
t.end();
|
56
|
+
});
|
57
|
+
|
58
|
+
test('short and long', function (t) {
|
59
|
+
t.deepEqual(
|
60
|
+
parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
|
61
|
+
{
|
62
|
+
f : true, p : 555, h : 'localhost',
|
63
|
+
_ : [ 'script.js' ]
|
64
|
+
}
|
65
|
+
);
|
66
|
+
t.end();
|
67
|
+
});
|