coa 0.3.6 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +4 -1
- package/.travis.yml +11 -0
- package/GNUmakefile +22 -3
- package/README.md +6 -0
- package/index.js +1 -0
- package/lib/arg.js +18 -2
- package/lib/cmd.js +87 -18
- package/lib/color.js +1 -1
- package/lib/completion.js +2 -2
- package/lib/index.js +10 -0
- package/lib/opt.js +14 -1
- package/lib/shell.js +1 -2
- package/package.json +12 -4
- package/src/arg.coffee +15 -1
- package/src/cmd.coffee +77 -18
- package/src/index.coffee +5 -0
- package/src/opt.coffee +10 -0
- package/test/coa.js +496 -0
- package/test/common.js +1 -0
- package/test/mocha.opts +3 -0
- package/test/shell-test.js +43 -42
- package/tests/api-h.js +2 -2
- package/tests/h.js +1 -1
- package/lib/coa.js +0 -3
- package/src/coa.coffee +0 -1
- package/tests/a.js +0 -14
- package/tests/api-args.js +0 -34
- package/tests/api-cmd.js +0 -27
- package/tests/args.js +0 -21
- package/tests/cmd.js +0 -14
- package/tests/def.js +0 -25
- package/tests/l.js +0 -21
- package/tests/rarg.js +0 -13
- package/tests/req.js +0 -10
- package/tests/v.js +0 -23
- package/tests/val.js +0 -14
package/test/coa.js
ADDED
@@ -0,0 +1,496 @@
|
|
1
|
+
var assert = require('chai').assert,
|
2
|
+
COA = require('..');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Mocha BDD interface.
|
6
|
+
*/
|
7
|
+
/** @name describe @function */
|
8
|
+
/** @name it @function */
|
9
|
+
/** @name before @function */
|
10
|
+
/** @name after @function */
|
11
|
+
/** @name beforeEach @function */
|
12
|
+
/** @name afterEach @function */
|
13
|
+
|
14
|
+
describe('Opt', function() {
|
15
|
+
|
16
|
+
describe('Unknown option', function() {
|
17
|
+
|
18
|
+
var cmd = COA.Cmd();
|
19
|
+
|
20
|
+
it('should fail', function() {
|
21
|
+
return cmd.do(['-a'])
|
22
|
+
.then(assert.fail, emptyFn);
|
23
|
+
});
|
24
|
+
|
25
|
+
});
|
26
|
+
|
27
|
+
describe('Short options', function() {
|
28
|
+
|
29
|
+
var cmd = COA.Cmd()
|
30
|
+
.opt()
|
31
|
+
.name('a')
|
32
|
+
.short('a')
|
33
|
+
.end()
|
34
|
+
.opt()
|
35
|
+
.name('b')
|
36
|
+
.short('b')
|
37
|
+
.end()
|
38
|
+
.act(function(opts) {
|
39
|
+
return opts;
|
40
|
+
});
|
41
|
+
|
42
|
+
it('should return passed values', function() {
|
43
|
+
return cmd.do(['-a', 'a', '-b', 'b'])
|
44
|
+
.then(function(res) {
|
45
|
+
assert.deepEqual(res, { a: 'a', b: 'b' });
|
46
|
+
});
|
47
|
+
});
|
48
|
+
|
49
|
+
});
|
50
|
+
|
51
|
+
describe('Long options', function() {
|
52
|
+
|
53
|
+
var cmd = COA.Cmd()
|
54
|
+
.opt()
|
55
|
+
.name('long1')
|
56
|
+
.long('long1')
|
57
|
+
.end()
|
58
|
+
.opt()
|
59
|
+
.name('long2')
|
60
|
+
.long('long2')
|
61
|
+
.end()
|
62
|
+
.act(function(opts) {
|
63
|
+
return opts;
|
64
|
+
});
|
65
|
+
|
66
|
+
it('should return passed values', function() {
|
67
|
+
return cmd.do(['--long1', 'long value', '--long2=another long value'])
|
68
|
+
.then(function(res) {
|
69
|
+
assert.deepEqual(res, { long1: 'long value', long2: 'another long value' });
|
70
|
+
});
|
71
|
+
});
|
72
|
+
|
73
|
+
});
|
74
|
+
|
75
|
+
describe('Array option', function() {
|
76
|
+
|
77
|
+
var cmd = COA.Cmd()
|
78
|
+
.opt()
|
79
|
+
.name('a')
|
80
|
+
.short('a')
|
81
|
+
.arr()
|
82
|
+
.end()
|
83
|
+
.act(function(opts) {
|
84
|
+
return opts;
|
85
|
+
});
|
86
|
+
|
87
|
+
it('should return array of passed values', function() {
|
88
|
+
return cmd.do(['-a', '1', '-a', '2'])
|
89
|
+
.then(function(res) {
|
90
|
+
assert.deepEqual(res, { a: ['1', '2'] });
|
91
|
+
});
|
92
|
+
});
|
93
|
+
|
94
|
+
});
|
95
|
+
|
96
|
+
describe('Required option', function() {
|
97
|
+
|
98
|
+
var cmd = COA.Cmd()
|
99
|
+
.opt()
|
100
|
+
.name('a')
|
101
|
+
.short('a')
|
102
|
+
.req()
|
103
|
+
.end()
|
104
|
+
.act(function(opts) {
|
105
|
+
return opts;
|
106
|
+
});
|
107
|
+
|
108
|
+
it('should fail if not specified', function() {
|
109
|
+
return cmd.do()
|
110
|
+
.then(assert.fail, emptyFn);
|
111
|
+
});
|
112
|
+
|
113
|
+
it('should return passed value if specified', function() {
|
114
|
+
return cmd.do(['-a', 'test'])
|
115
|
+
.then(function(opts) {
|
116
|
+
assert.equal(opts.a, 'test');
|
117
|
+
});
|
118
|
+
});
|
119
|
+
|
120
|
+
});
|
121
|
+
|
122
|
+
describe('Option with default value', function() {
|
123
|
+
|
124
|
+
var cmd = COA.Cmd()
|
125
|
+
.opt()
|
126
|
+
.name('a')
|
127
|
+
.short('a')
|
128
|
+
.def('aaa')
|
129
|
+
.end()
|
130
|
+
.act(function(opts) {
|
131
|
+
return opts;
|
132
|
+
});
|
133
|
+
|
134
|
+
it('should return default value if not specified', function() {
|
135
|
+
return cmd.do()
|
136
|
+
.then(function(opts) {
|
137
|
+
assert.equal(opts.a, 'aaa');
|
138
|
+
});
|
139
|
+
});
|
140
|
+
|
141
|
+
it('should return passed value if specified', function() {
|
142
|
+
return cmd.do(['-a', 'test'])
|
143
|
+
.then(function(opts) {
|
144
|
+
assert.equal(opts.a, 'test');
|
145
|
+
});
|
146
|
+
});
|
147
|
+
|
148
|
+
});
|
149
|
+
|
150
|
+
describe('Validated / transformed option', function() {
|
151
|
+
|
152
|
+
var cmd = COA.Cmd()
|
153
|
+
.opt()
|
154
|
+
.name('a')
|
155
|
+
.short('a')
|
156
|
+
.val(function(v) {
|
157
|
+
if (v === 'invalid') return this.reject('fail');
|
158
|
+
return { value: v };
|
159
|
+
})
|
160
|
+
.end()
|
161
|
+
.act(function(opts) {
|
162
|
+
return opts;
|
163
|
+
});
|
164
|
+
|
165
|
+
it('should fail if custom checks suppose to do so', function() {
|
166
|
+
return cmd.do(['-a', 'invalid'])
|
167
|
+
.then(assert.fail, emptyFn);
|
168
|
+
});
|
169
|
+
|
170
|
+
it('should return transformed value', function() {
|
171
|
+
return cmd.do(['-a', 'test'])
|
172
|
+
.then(function(opts) {
|
173
|
+
assert.deepEqual(opts.a, { value: 'test' });
|
174
|
+
});
|
175
|
+
});
|
176
|
+
|
177
|
+
});
|
178
|
+
|
179
|
+
describe('Only option (--version case)', function() {
|
180
|
+
|
181
|
+
var ver = require('../package.json').version,
|
182
|
+
cmd = COA.Cmd()
|
183
|
+
.opt()
|
184
|
+
.name('version')
|
185
|
+
.long('version')
|
186
|
+
.flag()
|
187
|
+
.only()
|
188
|
+
.act(function() {
|
189
|
+
return ver;
|
190
|
+
})
|
191
|
+
.end()
|
192
|
+
.opt()
|
193
|
+
.name('req')
|
194
|
+
.short('r')
|
195
|
+
.req()
|
196
|
+
.end();
|
197
|
+
|
198
|
+
it('should process the only() option', function() {
|
199
|
+
return cmd.do(['--version'])
|
200
|
+
.then(assert.fail, function(res) {
|
201
|
+
assert.equal(res, ver);
|
202
|
+
});
|
203
|
+
});
|
204
|
+
|
205
|
+
});
|
206
|
+
|
207
|
+
it('input()');
|
208
|
+
it('output()');
|
209
|
+
|
210
|
+
});
|
211
|
+
|
212
|
+
describe('Arg', function() {
|
213
|
+
|
214
|
+
describe('Unknown arg', function() {
|
215
|
+
|
216
|
+
var cmd = COA.Cmd();
|
217
|
+
|
218
|
+
it('should fail', function() {
|
219
|
+
return cmd.do(['test'])
|
220
|
+
.then(assert.fail, emptyFn);
|
221
|
+
});
|
222
|
+
|
223
|
+
});
|
224
|
+
|
225
|
+
describe('Unknown arg after known', function() {
|
226
|
+
|
227
|
+
var cmd = COA.Cmd()
|
228
|
+
.arg()
|
229
|
+
.name('a')
|
230
|
+
.end();
|
231
|
+
|
232
|
+
it('should fail', function() {
|
233
|
+
return cmd.do(['test', 'unknown'])
|
234
|
+
.then(assert.fail, emptyFn);
|
235
|
+
});
|
236
|
+
|
237
|
+
});
|
238
|
+
|
239
|
+
describe('Array arg', function() {
|
240
|
+
|
241
|
+
var cmd = COA.Cmd()
|
242
|
+
.arg()
|
243
|
+
.name('a')
|
244
|
+
.arr()
|
245
|
+
.end()
|
246
|
+
.act(function(opts, args) {
|
247
|
+
return args;
|
248
|
+
});
|
249
|
+
|
250
|
+
it('should return array of passed values', function() {
|
251
|
+
return cmd.do(['value 1', 'value 2'])
|
252
|
+
.then(function(args) {
|
253
|
+
assert.deepEqual(args, { a: ['value 1', 'value 2'] });
|
254
|
+
});
|
255
|
+
});
|
256
|
+
|
257
|
+
});
|
258
|
+
|
259
|
+
describe('Required arg', function() {
|
260
|
+
|
261
|
+
var cmd = COA.Cmd()
|
262
|
+
.arg()
|
263
|
+
.name('a')
|
264
|
+
.req()
|
265
|
+
.end()
|
266
|
+
.act(function(opts, args) {
|
267
|
+
return args;
|
268
|
+
});
|
269
|
+
|
270
|
+
it('should fail if not specified', function() {
|
271
|
+
return cmd.do()
|
272
|
+
.then(assert.fail, emptyFn);
|
273
|
+
});
|
274
|
+
|
275
|
+
it('should return passed value if specified', function() {
|
276
|
+
return cmd.do(['value'])
|
277
|
+
.then(function(args) {
|
278
|
+
assert.equal(args.a, 'value');
|
279
|
+
});
|
280
|
+
});
|
281
|
+
|
282
|
+
});
|
283
|
+
|
284
|
+
describe('Args after options', function() {
|
285
|
+
|
286
|
+
var cmd = COA.Cmd()
|
287
|
+
.opt()
|
288
|
+
.name('opt')
|
289
|
+
.long('opt')
|
290
|
+
.end()
|
291
|
+
.arg()
|
292
|
+
.name('arg1')
|
293
|
+
.end()
|
294
|
+
.arg()
|
295
|
+
.name('arg2')
|
296
|
+
.arr()
|
297
|
+
.end()
|
298
|
+
.act(function(opts, args) {
|
299
|
+
return { opts: opts, args: args };
|
300
|
+
});
|
301
|
+
|
302
|
+
it('should return passed values', function() {
|
303
|
+
return cmd.do(['--opt', 'value', 'value', 'value 1', 'value 2'])
|
304
|
+
.then(function(o) {
|
305
|
+
assert.deepEqual(o, {
|
306
|
+
opts: { opt: 'value' },
|
307
|
+
args: {
|
308
|
+
arg1: 'value',
|
309
|
+
arg2: ['value 1', 'value 2']
|
310
|
+
}
|
311
|
+
});
|
312
|
+
});
|
313
|
+
});
|
314
|
+
|
315
|
+
});
|
316
|
+
|
317
|
+
describe('Raw args', function() {
|
318
|
+
|
319
|
+
var cmd = COA.Cmd()
|
320
|
+
.arg()
|
321
|
+
.name('raw')
|
322
|
+
.arr()
|
323
|
+
.end()
|
324
|
+
.act(function(opts, args) {
|
325
|
+
return args;
|
326
|
+
});
|
327
|
+
|
328
|
+
it('should return passed arg values', function() {
|
329
|
+
return cmd.do(['--', 'raw', 'arg', 'values'])
|
330
|
+
.then(function(args) {
|
331
|
+
assert.deepEqual(args, { raw: ['raw', 'arg', 'values'] });
|
332
|
+
});
|
333
|
+
});
|
334
|
+
|
335
|
+
});
|
336
|
+
|
337
|
+
});
|
338
|
+
|
339
|
+
describe('Cmd', function() {
|
340
|
+
|
341
|
+
var doTest = function(o) {
|
342
|
+
assert.deepEqual(o, {
|
343
|
+
opts: { opt: 'value' },
|
344
|
+
args: {
|
345
|
+
arg1: 'value',
|
346
|
+
arg2: ['value 1', 'value 2']
|
347
|
+
}
|
348
|
+
});
|
349
|
+
},
|
350
|
+
|
351
|
+
invokeOpts = { opt: 'value' },
|
352
|
+
invokeArgs = {
|
353
|
+
arg1: 'value',
|
354
|
+
arg2: ['value 1', 'value 2']
|
355
|
+
};
|
356
|
+
|
357
|
+
describe('Subcommand', function() {
|
358
|
+
|
359
|
+
var cmd = COA.Cmd()
|
360
|
+
.cmd()
|
361
|
+
.name('command')
|
362
|
+
.opt()
|
363
|
+
.name('opt')
|
364
|
+
.long('opt')
|
365
|
+
.end()
|
366
|
+
.arg()
|
367
|
+
.name('arg1')
|
368
|
+
.end()
|
369
|
+
.arg()
|
370
|
+
.name('arg2')
|
371
|
+
.arr()
|
372
|
+
.end()
|
373
|
+
.act(function(opts, args) {
|
374
|
+
return { opts: opts, args: args };
|
375
|
+
})
|
376
|
+
.end();
|
377
|
+
|
378
|
+
describe('when specified on command line', function() {
|
379
|
+
|
380
|
+
it('should be invoked and accept passed opts and args', function() {
|
381
|
+
return cmd.do(['command', '--opt', 'value', 'value', 'value 1', 'value 2'])
|
382
|
+
.then(doTest);
|
383
|
+
});
|
384
|
+
|
385
|
+
});
|
386
|
+
|
387
|
+
describe('when invoked using api', function() {
|
388
|
+
|
389
|
+
it('should be invoked and accept passed opts and args', function() {
|
390
|
+
return cmd.api.command(invokeOpts, invokeArgs)
|
391
|
+
.then(doTest);
|
392
|
+
});
|
393
|
+
|
394
|
+
});
|
395
|
+
|
396
|
+
describe('when invoked using invoke()', function() {
|
397
|
+
|
398
|
+
it('should be invoked and accept passed opts and args', function() {
|
399
|
+
return cmd.invoke('command', invokeOpts, invokeArgs)
|
400
|
+
.then(doTest);
|
401
|
+
});
|
402
|
+
|
403
|
+
});
|
404
|
+
|
405
|
+
describe('when unexisting command invoked using invoke()', function() {
|
406
|
+
|
407
|
+
it('should fail', function() {
|
408
|
+
return cmd.invoke('unexistent')
|
409
|
+
.then(assert.fail, emptyFn);
|
410
|
+
});
|
411
|
+
|
412
|
+
});
|
413
|
+
|
414
|
+
});
|
415
|
+
|
416
|
+
describe('External subcommand', function() {
|
417
|
+
|
418
|
+
describe('default scheme: cmd.extendable()', function() {
|
419
|
+
|
420
|
+
describe('when described as a function', function() {
|
421
|
+
var cmd = COA.Cmd()
|
422
|
+
.name('coa')
|
423
|
+
.extendable();
|
424
|
+
|
425
|
+
it('should be invoked and accept passed opts and args', function() {
|
426
|
+
return cmd.do(['test', '--opt', 'value', 'value', 'value 1', 'value 2'])
|
427
|
+
.then(doTest);
|
428
|
+
});
|
429
|
+
});
|
430
|
+
|
431
|
+
describe('when described as an COA.Cmd() object', function() {
|
432
|
+
var cmd = COA.Cmd()
|
433
|
+
.name('coa')
|
434
|
+
.extendable();
|
435
|
+
|
436
|
+
it('should be invoked and accept passed opts and args', function() {
|
437
|
+
return cmd.do(['test-obj', '--opt', 'value', 'value', 'value 1', 'value 2'])
|
438
|
+
.then(doTest);
|
439
|
+
});
|
440
|
+
});
|
441
|
+
|
442
|
+
describe('2nd level subcommand', function() {
|
443
|
+
var cmd = COA.Cmd()
|
444
|
+
.name('coa')
|
445
|
+
.cmd()
|
446
|
+
.name('test')
|
447
|
+
.extendable()
|
448
|
+
.end();
|
449
|
+
|
450
|
+
it('should be invoked and accept passed opts and args', function() {
|
451
|
+
return cmd.do(['test', 'obj', '--opt', 'value', 'value', 'value 1', 'value 2'])
|
452
|
+
.then(doTest);
|
453
|
+
});
|
454
|
+
});
|
455
|
+
|
456
|
+
});
|
457
|
+
|
458
|
+
describe("common prefix: cmd.extendable('coa-')", function() {
|
459
|
+
|
460
|
+
describe('when described as a function', function() {
|
461
|
+
var cmd = COA.Cmd()
|
462
|
+
.name('coa')
|
463
|
+
.extendable('coa-');
|
464
|
+
|
465
|
+
it('should be invoked and accept passed opts and args', function() {
|
466
|
+
return cmd.do(['test', '--opt', 'value', 'value', 'value 1', 'value 2'])
|
467
|
+
.then(doTest);
|
468
|
+
});
|
469
|
+
});
|
470
|
+
|
471
|
+
});
|
472
|
+
|
473
|
+
describe("format string: cmd.extendable('coa-%s')", function() {
|
474
|
+
|
475
|
+
describe('when described as a function', function() {
|
476
|
+
var cmd = COA.Cmd()
|
477
|
+
.name('coa')
|
478
|
+
.extendable('coa-%s');
|
479
|
+
|
480
|
+
it('should be invoked and accept passed opts and args', function() {
|
481
|
+
return cmd.do(['test', '--opt', 'value', 'value', 'value 1', 'value 2'])
|
482
|
+
.then(doTest);
|
483
|
+
});
|
484
|
+
});
|
485
|
+
|
486
|
+
});
|
487
|
+
|
488
|
+
});
|
489
|
+
|
490
|
+
it('helpful(), name(), title()');
|
491
|
+
|
492
|
+
});
|
493
|
+
|
494
|
+
function emptyFn() {
|
495
|
+
// empty function
|
496
|
+
}
|
package/test/common.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require('mocha-as-promised')(require('mocha'));
|
package/test/mocha.opts
ADDED
package/test/shell-test.js
CHANGED
@@ -1,59 +1,60 @@
|
|
1
|
-
var
|
2
|
-
|
3
|
-
shell = require('../lib/shell');
|
1
|
+
var assert = require('chai').assert,
|
2
|
+
shell = require('..').shell;
|
4
3
|
|
5
|
-
|
4
|
+
/**
|
5
|
+
* Mocha BDD interface.
|
6
|
+
*/
|
7
|
+
/** @name describe @function */
|
8
|
+
/** @name it @function */
|
9
|
+
/** @name before @function */
|
10
|
+
/** @name after @function */
|
11
|
+
/** @name beforeEach @function */
|
12
|
+
/** @name afterEach @function */
|
6
13
|
|
7
|
-
|
14
|
+
describe('shell', function() {
|
8
15
|
|
9
|
-
|
16
|
+
describe('escape()', function() {
|
10
17
|
|
11
|
-
|
12
|
-
return shell.escape;
|
13
|
-
},
|
18
|
+
var escape = shell.escape;
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
20
|
+
it('Should wrap values with spaces in double quotes', function() {
|
21
|
+
assert.equal(escape('asd abc'), '"asd abc"');
|
22
|
+
});
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
it('Should escape double quote "', function() {
|
25
|
+
assert.equal(escape('"asd'), '\\"asd');
|
26
|
+
});
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
it("Should escape single quote '", function() {
|
29
|
+
assert.equal(escape("'asd"), "\\'asd");
|
30
|
+
});
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
it('Should escape backslash \\', function() {
|
33
|
+
assert.equal(escape('\\asd'), '\\\\asd');
|
34
|
+
});
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
it('Should escape dollar $', function() {
|
37
|
+
assert.equal(escape('$asd'), '\\$asd');
|
38
|
+
});
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
it('Should escape backtick `', function() {
|
41
|
+
assert.equal(escape('`asd'), '\\`asd');
|
42
|
+
});
|
38
43
|
|
39
|
-
|
44
|
+
});
|
40
45
|
|
41
|
-
|
46
|
+
describe('unescape()', function() {
|
42
47
|
|
43
|
-
|
44
|
-
return shell.unescape;
|
45
|
-
},
|
48
|
+
var unescape = shell.unescape;
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
it('Should strip double quotes at the both ends', function() {
|
51
|
+
assert.equal(unescape('"asd"'), 'asd');
|
52
|
+
});
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
it('Should not strip escaped double quotes at the both ends', function() {
|
55
|
+
assert.equal(unescape('\\"asd\\"'), '"asd"');
|
56
|
+
});
|
54
57
|
|
55
|
-
|
58
|
+
});
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
}).export(module);
|
60
|
+
});
|
package/tests/api-h.js
CHANGED
package/tests/h.js
CHANGED
package/lib/coa.js
DELETED
package/src/coa.coffee
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
exports.Cmd = require('./cmd').Cmd
|
package/tests/a.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
var argv = process.argv.slice(2);
|
2
|
-
require('../lib/coa').Cmd()
|
3
|
-
.name('arr')
|
4
|
-
.title('Array value test')
|
5
|
-
.helpful()
|
6
|
-
.opt()
|
7
|
-
.name('arr').title('Array')
|
8
|
-
.short('a').long('arr')
|
9
|
-
.arr()
|
10
|
-
.act(function(opts) {
|
11
|
-
console.log(opts.arr);
|
12
|
-
})
|
13
|
-
.end()
|
14
|
-
.run(argv.length? argv : ['-a', '1', '-a', '2']);
|
package/tests/api-args.js
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require('../lib/coa').Cmd()
|
2
|
-
.name('arg')
|
3
|
-
.title('Args test')
|
4
|
-
.helpful()
|
5
|
-
.opt()
|
6
|
-
.name('opt').title('Option')
|
7
|
-
.long('opt').short('o')
|
8
|
-
.val(function(v) {
|
9
|
-
return v.toUpperCase();
|
10
|
-
})
|
11
|
-
.end()
|
12
|
-
.opt()
|
13
|
-
.name('def').title('Option with default value')
|
14
|
-
.long('def').short('d')
|
15
|
-
.def('default value')
|
16
|
-
.end()
|
17
|
-
.arg()
|
18
|
-
.name('arg1').title('First arg')
|
19
|
-
.end()
|
20
|
-
.arg()
|
21
|
-
.name('arg2').title('Second array arg')
|
22
|
-
.arr()
|
23
|
-
.end()
|
24
|
-
.act(function(opts, args) {
|
25
|
-
console.log(opts);
|
26
|
-
console.log(args);
|
27
|
-
})
|
28
|
-
.invoke(
|
29
|
-
{ opt: 'value' },
|
30
|
-
{
|
31
|
-
arg1: 'value',
|
32
|
-
arg2: ['value 1', 'value 2']
|
33
|
-
})
|
34
|
-
.end();
|