commander 0.4.2 → 0.5.2
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/History.md +28 -0
- package/Readme.md +2 -3
- package/lib/commander.js +140 -38
- package/package.json +2 -2
- package/.gitignore +0 -3
- package/examples/choice +0 -15
- package/examples/coercion +0 -33
- package/examples/confirm +0 -12
- package/examples/custom-help +0 -32
- package/examples/defaults +0 -22
- package/examples/deploy +0 -38
- package/examples/express +0 -18
- package/examples/input +0 -24
- package/examples/password +0 -18
- package/examples/pizza +0 -28
- package/test/run +0 -16
- package/test/test.literal.args.js +0 -16
- package/test/test.options.args.optional.given.js +0 -13
- package/test/test.options.args.optional.js +0 -13
- package/test/test.options.bool.js +0 -16
- package/test/test.options.bool.no.js +0 -15
- package/test/test.options.bool.small.combined.js +0 -15
- package/test/test.options.bool.small.js +0 -15
- package/test/test.options.camelcase.js +0 -27
- package/test/test.options.coercion.js +0 -23
- package/test/test.options.defaults.given.js +0 -23
- package/test/test.options.defaults.js +0 -23
- package/test/test.options.large-only-with-value.js +0 -13
- package/test/test.options.large-only.js +0 -13
package/History.md
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
|
|
2
|
+
0.6.1 / 2012-06-01
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* Added: append (yes or no) on confirmation
|
|
6
|
+
* Added: allow node.js v0.7.x
|
|
7
|
+
|
|
8
|
+
0.6.0 / 2012-04-10
|
|
9
|
+
==================
|
|
10
|
+
|
|
11
|
+
* Added `.prompt(obj, callback)` support. Closes #49
|
|
12
|
+
* Added default support to .choose(). Closes #41
|
|
13
|
+
* Fixed the choice example
|
|
14
|
+
|
|
15
|
+
0.5.1 / 2011-12-20
|
|
16
|
+
==================
|
|
17
|
+
|
|
18
|
+
* Fixed `password()` for recent nodes. Closes #36
|
|
19
|
+
|
|
20
|
+
0.5.0 / 2011-12-04
|
|
21
|
+
==================
|
|
22
|
+
|
|
23
|
+
* Added sub-command option support [itay]
|
|
24
|
+
|
|
25
|
+
0.4.3 / 2011-12-04
|
|
26
|
+
==================
|
|
27
|
+
|
|
28
|
+
* Fixed custom help ordering. Closes #32
|
|
29
|
+
|
|
2
30
|
0.4.2 / 2011-11-24
|
|
3
31
|
==================
|
|
4
32
|
|
package/Readme.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# Commander.js
|
|
3
2
|
|
|
4
3
|
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/visionmedia/commander).
|
|
@@ -50,7 +49,7 @@ console.log(' - %s cheese', program.cheese);
|
|
|
50
49
|
|
|
51
50
|
Options:
|
|
52
51
|
|
|
53
|
-
-
|
|
52
|
+
-V, --version output the version number
|
|
54
53
|
-p, --peppers Add peppers
|
|
55
54
|
-P, --pineapple Add pineappe
|
|
56
55
|
-b, --bbq Add bbq sauce
|
|
@@ -142,7 +141,7 @@ Usage: custom-help [options]
|
|
|
142
141
|
Options:
|
|
143
142
|
|
|
144
143
|
-h, --help output usage information
|
|
145
|
-
-
|
|
144
|
+
-V, --version output the version number
|
|
146
145
|
-f, --foo enable some foo
|
|
147
146
|
-b, --bar enable some bar
|
|
148
147
|
-B, --baz enable some baz
|
package/lib/commander.js
CHANGED
|
@@ -199,12 +199,36 @@ Command.prototype.parseExpectedArgs = function(args){
|
|
|
199
199
|
|
|
200
200
|
Command.prototype.action = function(fn){
|
|
201
201
|
var self = this;
|
|
202
|
-
this.parent.on(this.name, function(args){
|
|
202
|
+
this.parent.on(this.name, function(args, unknown){
|
|
203
|
+
// Parse any so-far unknown options
|
|
204
|
+
unknown = unknown || [];
|
|
205
|
+
var parsed = self.parseOptions(unknown);
|
|
206
|
+
|
|
207
|
+
// Output help if necessary
|
|
208
|
+
outputHelpIfNecessary(self, parsed.unknown);
|
|
209
|
+
|
|
210
|
+
// If there are still any unknown options, then we simply
|
|
211
|
+
// die, unless someone asked for help, in which case we give it
|
|
212
|
+
// to them, and then we die.
|
|
213
|
+
if (parsed.unknown.length > 0) {
|
|
214
|
+
self.unknownOption(parsed.unknown[0]);
|
|
215
|
+
}
|
|
216
|
+
|
|
203
217
|
self.args.forEach(function(arg, i){
|
|
204
218
|
if (arg.required && null == args[i]) {
|
|
205
219
|
self.missingArgument(arg.name);
|
|
206
220
|
}
|
|
207
221
|
});
|
|
222
|
+
|
|
223
|
+
// Always append ourselves to the end of the arguments,
|
|
224
|
+
// to make sure we match the number of arguments the user
|
|
225
|
+
// expects
|
|
226
|
+
if (self.args.length) {
|
|
227
|
+
args[self.args.length] = self;
|
|
228
|
+
} else {
|
|
229
|
+
args.push(self);
|
|
230
|
+
}
|
|
231
|
+
|
|
208
232
|
fn.apply(this, args);
|
|
209
233
|
});
|
|
210
234
|
return this;
|
|
@@ -320,8 +344,9 @@ Command.prototype.parse = function(argv){
|
|
|
320
344
|
if (!this.name) this.name = basename(argv[1]);
|
|
321
345
|
|
|
322
346
|
// process argv
|
|
323
|
-
|
|
324
|
-
|
|
347
|
+
var parsed = this.parseOptions(this.normalize(argv.slice(2)));
|
|
348
|
+
this.args = parsed.args;
|
|
349
|
+
return this.parseArgs(this.args, parsed.unknown);
|
|
325
350
|
};
|
|
326
351
|
|
|
327
352
|
/**
|
|
@@ -363,7 +388,7 @@ Command.prototype.normalize = function(args){
|
|
|
363
388
|
* @api private
|
|
364
389
|
*/
|
|
365
390
|
|
|
366
|
-
Command.prototype.parseArgs = function(args){
|
|
391
|
+
Command.prototype.parseArgs = function(args, unknown){
|
|
367
392
|
var cmds = this.commands
|
|
368
393
|
, len = cmds.length
|
|
369
394
|
, name;
|
|
@@ -371,10 +396,18 @@ Command.prototype.parseArgs = function(args){
|
|
|
371
396
|
if (args.length) {
|
|
372
397
|
name = args[0];
|
|
373
398
|
if (this.listeners(name).length) {
|
|
374
|
-
this.emit(args.shift(), args);
|
|
399
|
+
this.emit(args.shift(), args, unknown);
|
|
375
400
|
} else {
|
|
376
401
|
this.emit('*', args);
|
|
377
402
|
}
|
|
403
|
+
} else {
|
|
404
|
+
outputHelpIfNecessary(this, unknown);
|
|
405
|
+
|
|
406
|
+
// If there were no args and we have unknown options,
|
|
407
|
+
// then they are extraneous and we need to error.
|
|
408
|
+
if (unknown.length > 0) {
|
|
409
|
+
this.unknownOption(unknown[0]);
|
|
410
|
+
}
|
|
378
411
|
}
|
|
379
412
|
|
|
380
413
|
return this;
|
|
@@ -407,12 +440,13 @@ Command.prototype.optionFor = function(arg){
|
|
|
407
440
|
|
|
408
441
|
Command.prototype.parseOptions = function(argv){
|
|
409
442
|
var args = []
|
|
410
|
-
, argv = argv.slice(2)
|
|
411
443
|
, len = argv.length
|
|
412
444
|
, literal
|
|
413
445
|
, option
|
|
414
446
|
, arg;
|
|
415
447
|
|
|
448
|
+
var unknownOptions = [];
|
|
449
|
+
|
|
416
450
|
// parse options
|
|
417
451
|
for (var i = 0; i < len; ++i) {
|
|
418
452
|
arg = argv[i];
|
|
@@ -457,14 +491,22 @@ Command.prototype.parseOptions = function(argv){
|
|
|
457
491
|
|
|
458
492
|
// looks like an option
|
|
459
493
|
if (arg.length > 1 && '-' == arg[0]) {
|
|
460
|
-
|
|
494
|
+
unknownOptions.push(arg);
|
|
495
|
+
|
|
496
|
+
// If the next argument looks like it might be
|
|
497
|
+
// an argument for this option, we pass it on.
|
|
498
|
+
// If it isn't, then it'll simply be ignored
|
|
499
|
+
if (argv[i+1] && '-' != argv[i+1][0]) {
|
|
500
|
+
unknownOptions.push(argv[++i]);
|
|
501
|
+
}
|
|
502
|
+
continue;
|
|
461
503
|
}
|
|
462
504
|
|
|
463
505
|
// arg
|
|
464
506
|
args.push(arg);
|
|
465
507
|
}
|
|
466
|
-
|
|
467
|
-
return args;
|
|
508
|
+
|
|
509
|
+
return { args: args, unknown: unknownOptions };
|
|
468
510
|
};
|
|
469
511
|
|
|
470
512
|
/**
|
|
@@ -561,11 +603,19 @@ Command.prototype.description = function(str){
|
|
|
561
603
|
*/
|
|
562
604
|
|
|
563
605
|
Command.prototype.usage = function(str){
|
|
606
|
+
var args = this.args.map(function(arg){
|
|
607
|
+
return arg.required
|
|
608
|
+
? '<' + arg.name + '>'
|
|
609
|
+
: '[' + arg.name + ']';
|
|
610
|
+
});
|
|
611
|
+
|
|
564
612
|
var usage = '[options'
|
|
565
613
|
+ (this.commands.length ? '] [command' : '')
|
|
566
|
-
+ ']'
|
|
614
|
+
+ ']'
|
|
615
|
+
+ (this.args.length ? ' ' + args : '');
|
|
567
616
|
if (0 == arguments.length) return this._usage || usage;
|
|
568
617
|
this._usage = str;
|
|
618
|
+
|
|
569
619
|
return this;
|
|
570
620
|
};
|
|
571
621
|
|
|
@@ -591,10 +641,14 @@ Command.prototype.largestOptionLength = function(){
|
|
|
591
641
|
|
|
592
642
|
Command.prototype.optionHelp = function(){
|
|
593
643
|
var width = this.largestOptionLength();
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
644
|
+
|
|
645
|
+
// Prepend the help information
|
|
646
|
+
return [pad('-h, --help', width) + ' ' + 'output usage information']
|
|
647
|
+
.concat(this.options.map(function(option){
|
|
648
|
+
return pad(option.flags, width)
|
|
649
|
+
+ ' ' + option.description;
|
|
650
|
+
}))
|
|
651
|
+
.join('\n');
|
|
598
652
|
};
|
|
599
653
|
|
|
600
654
|
/**
|
|
@@ -616,7 +670,11 @@ Command.prototype.commandHelp = function(){
|
|
|
616
670
|
? '<' + arg.name + '>'
|
|
617
671
|
: '[' + arg.name + ']';
|
|
618
672
|
}).join(' ');
|
|
619
|
-
|
|
673
|
+
|
|
674
|
+
return cmd.name
|
|
675
|
+
+ (cmd.options.length
|
|
676
|
+
? ' [options]'
|
|
677
|
+
: '') + ' ' + args
|
|
620
678
|
+ (cmd.description()
|
|
621
679
|
? '\n' + cmd.description()
|
|
622
680
|
: '');
|
|
@@ -654,9 +712,10 @@ Command.prototype.helpInformation = function(){
|
|
|
654
712
|
*/
|
|
655
713
|
|
|
656
714
|
Command.prototype.promptForNumber = function(str, fn){
|
|
657
|
-
this
|
|
715
|
+
var self = this;
|
|
716
|
+
this.promptSingleLine(str, function parseNumber(val){
|
|
658
717
|
val = Number(val);
|
|
659
|
-
if (isNaN(val)) return
|
|
718
|
+
if (isNaN(val)) return self.promptSingleLine(str + '(must be a number) ', parseNumber);
|
|
660
719
|
fn(val);
|
|
661
720
|
});
|
|
662
721
|
};
|
|
@@ -671,9 +730,9 @@ Command.prototype.promptForNumber = function(str, fn){
|
|
|
671
730
|
|
|
672
731
|
Command.prototype.promptForDate = function(str, fn){
|
|
673
732
|
var self = this;
|
|
674
|
-
this.promptSingleLine(str, function(val){
|
|
733
|
+
this.promptSingleLine(str, function parseDate(val){
|
|
675
734
|
val = new Date(val);
|
|
676
|
-
if (isNaN(val.getTime())) return self.
|
|
735
|
+
if (isNaN(val.getTime())) return self.promptSingleLine(str + '(must be a date) ', parseDate);
|
|
677
736
|
fn(val);
|
|
678
737
|
});
|
|
679
738
|
};
|
|
@@ -707,15 +766,15 @@ Command.prototype.promptSingleLine = function(str, fn){
|
|
|
707
766
|
*/
|
|
708
767
|
|
|
709
768
|
Command.prototype.promptMultiLine = function(str, fn){
|
|
710
|
-
var buf =
|
|
769
|
+
var buf = [];
|
|
711
770
|
console.log(str);
|
|
712
771
|
process.stdin.setEncoding('utf8');
|
|
713
772
|
process.stdin.on('data', function(val){
|
|
714
|
-
if ('\n' == val) {
|
|
773
|
+
if ('\n' == val || '\r\n' == val) {
|
|
715
774
|
process.stdin.removeAllListeners('data');
|
|
716
|
-
fn(buf);
|
|
775
|
+
fn(buf.join('\n'));
|
|
717
776
|
} else {
|
|
718
|
-
buf
|
|
777
|
+
buf.push(val.trimRight());
|
|
719
778
|
}
|
|
720
779
|
}).resume();
|
|
721
780
|
};
|
|
@@ -739,14 +798,34 @@ Command.prototype.promptMultiLine = function(str, fn){
|
|
|
739
798
|
* console.log('description was "%s"', desc.trim());
|
|
740
799
|
* });
|
|
741
800
|
*
|
|
742
|
-
* @param {String} str
|
|
801
|
+
* @param {String|Object} str
|
|
743
802
|
* @param {Function} fn
|
|
744
803
|
* @api public
|
|
745
804
|
*/
|
|
746
805
|
|
|
747
806
|
Command.prototype.prompt = function(str, fn){
|
|
748
|
-
|
|
749
|
-
|
|
807
|
+
var self = this;
|
|
808
|
+
|
|
809
|
+
if ('string' == typeof str) {
|
|
810
|
+
if (/ $/.test(str)) return this.promptSingleLine.apply(this, arguments);
|
|
811
|
+
this.promptMultiLine(str, fn);
|
|
812
|
+
} else {
|
|
813
|
+
var keys = Object.keys(str)
|
|
814
|
+
, obj = {};
|
|
815
|
+
|
|
816
|
+
function next() {
|
|
817
|
+
var key = keys.shift()
|
|
818
|
+
, label = str[key];
|
|
819
|
+
|
|
820
|
+
if (!key) return fn(obj);
|
|
821
|
+
self.prompt(label, function(val){
|
|
822
|
+
obj[key] = val;
|
|
823
|
+
next();
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
next();
|
|
828
|
+
}
|
|
750
829
|
};
|
|
751
830
|
|
|
752
831
|
/**
|
|
@@ -783,6 +862,7 @@ Command.prototype.password = function(str, mask, fn){
|
|
|
783
862
|
mask = '';
|
|
784
863
|
}
|
|
785
864
|
|
|
865
|
+
process.stdin.resume();
|
|
786
866
|
tty.setRawMode(true);
|
|
787
867
|
process.stdout.write(str);
|
|
788
868
|
|
|
@@ -823,11 +903,12 @@ Command.prototype.password = function(str, mask, fn){
|
|
|
823
903
|
*/
|
|
824
904
|
|
|
825
905
|
|
|
826
|
-
Command.prototype.confirm = function(str, fn){
|
|
906
|
+
Command.prototype.confirm = function(str, fn, verbose){
|
|
827
907
|
var self = this;
|
|
828
908
|
this.prompt(str, function(ok){
|
|
829
909
|
if (!ok.trim()) {
|
|
830
|
-
|
|
910
|
+
if (!verbose) str += '(yes or no) ';
|
|
911
|
+
return self.confirm(str, fn, true);
|
|
831
912
|
}
|
|
832
913
|
fn(parseBool(ok));
|
|
833
914
|
});
|
|
@@ -847,20 +928,33 @@ Command.prototype.confirm = function(str, fn){
|
|
|
847
928
|
* });
|
|
848
929
|
*
|
|
849
930
|
* @param {Array} list
|
|
931
|
+
* @param {Number|Function} index or fn
|
|
850
932
|
* @param {Function} fn
|
|
851
933
|
* @api public
|
|
852
934
|
*/
|
|
853
935
|
|
|
854
|
-
Command.prototype.choose = function(list, fn){
|
|
855
|
-
var self = this
|
|
936
|
+
Command.prototype.choose = function(list, index, fn){
|
|
937
|
+
var self = this
|
|
938
|
+
, hasDefault = 'number' == typeof index;
|
|
939
|
+
|
|
940
|
+
if (!hasDefault) {
|
|
941
|
+
fn = index;
|
|
942
|
+
index = null;
|
|
943
|
+
}
|
|
856
944
|
|
|
857
945
|
list.forEach(function(item, i){
|
|
858
|
-
|
|
946
|
+
if (hasDefault && i == index) {
|
|
947
|
+
console.log('* %d) %s', i + 1, item);
|
|
948
|
+
} else {
|
|
949
|
+
console.log(' %d) %s', i + 1, item);
|
|
950
|
+
}
|
|
859
951
|
});
|
|
860
952
|
|
|
861
953
|
function again() {
|
|
862
954
|
self.prompt(' : ', function(val){
|
|
863
955
|
val = parseInt(val, 10) - 1;
|
|
956
|
+
if (hasDefault && isNaN(val)) val = index;
|
|
957
|
+
|
|
864
958
|
if (null == list[val]) {
|
|
865
959
|
again();
|
|
866
960
|
} else {
|
|
@@ -913,12 +1007,20 @@ function pad(str, width) {
|
|
|
913
1007
|
}
|
|
914
1008
|
|
|
915
1009
|
/**
|
|
916
|
-
*
|
|
1010
|
+
* Output help information if necessary
|
|
1011
|
+
*
|
|
1012
|
+
* @param {Command} command to output help for
|
|
1013
|
+
* @param {Array} array of options to search for -h or --help
|
|
1014
|
+
* @api private
|
|
917
1015
|
*/
|
|
918
1016
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1017
|
+
function outputHelpIfNecessary(cmd, options) {
|
|
1018
|
+
options = options || [];
|
|
1019
|
+
for (var i = 0; i < options.length; i++) {
|
|
1020
|
+
if (options[i] == '--help' || options[i] == '-h') {
|
|
1021
|
+
process.stdout.write(cmd.helpInformation());
|
|
1022
|
+
cmd.emit('--help');
|
|
1023
|
+
process.exit(0);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander"
|
|
3
|
-
, "version": "0.
|
|
3
|
+
, "version": "0.5.2"
|
|
4
4
|
, "description": "the complete solution for node.js command-line programs"
|
|
5
5
|
, "keywords": ["command", "option", "parser", "prompt", "stdin"]
|
|
6
6
|
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
, "devDependencies": { "should": ">= 0.0.1" }
|
|
10
10
|
, "scripts": { "test": "make test" }
|
|
11
11
|
, "main": "index"
|
|
12
|
-
, "engines": { "node": ">= 0.4.x
|
|
12
|
+
, "engines": { "node": ">= 0.4.x" }
|
|
13
13
|
}
|
package/.gitignore
DELETED
package/examples/choice
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
var list = ['tobi', 'loki', 'jane', 'manny', 'luna'];
|
|
10
|
-
|
|
11
|
-
console.log('Choose the coolest pet:');
|
|
12
|
-
program.choose(list, function(i){
|
|
13
|
-
console.log('you chose %d "%s"', i, list[i]);
|
|
14
|
-
process.stdin.destroy();
|
|
15
|
-
});
|
package/examples/coercion
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
function range(val) {
|
|
10
|
-
return val.split('..').map(Number);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function list(val) {
|
|
14
|
-
return val.split(',');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
program
|
|
18
|
-
.version('0.0.1')
|
|
19
|
-
.usage('test')
|
|
20
|
-
.option('-i, --integer <n>', 'An integer argument', parseInt)
|
|
21
|
-
.option('-f, --float <n>', 'A float argument', parseFloat)
|
|
22
|
-
.option('-r, --range <a>..<b>', 'A range', range)
|
|
23
|
-
.option('-l, --list <items>', 'A list', list)
|
|
24
|
-
.option('-o, --optional [value]', 'An optional value')
|
|
25
|
-
.parse(process.argv);
|
|
26
|
-
|
|
27
|
-
console.log(' int: %j', program.integer);
|
|
28
|
-
console.log(' float: %j', program.float);
|
|
29
|
-
console.log(' optional: %j', program.optional);
|
|
30
|
-
program.range = program.range || [];
|
|
31
|
-
console.log(' range: %j..%j', program.range[0], program.range[1]);
|
|
32
|
-
console.log(' list: %j', program.list);
|
|
33
|
-
console.log(' args: %j', program.args);
|
package/examples/confirm
DELETED
package/examples/custom-help
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
function list(val) {
|
|
10
|
-
return val.split(',').map(Number);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
program
|
|
14
|
-
.version('0.0.1')
|
|
15
|
-
.option('-f, --foo', 'enable some foo')
|
|
16
|
-
.option('-b, --bar', 'enable some bar')
|
|
17
|
-
.option('-B, --baz', 'enable some baz');
|
|
18
|
-
|
|
19
|
-
// must be before .parse() since
|
|
20
|
-
// node's emit() is immediate
|
|
21
|
-
|
|
22
|
-
program.on('--help', function(){
|
|
23
|
-
console.log(' Examples:');
|
|
24
|
-
console.log('');
|
|
25
|
-
console.log(' $ custom-help --help');
|
|
26
|
-
console.log(' $ custom-help -h');
|
|
27
|
-
console.log('');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
program.parse(process.argv);
|
|
31
|
-
|
|
32
|
-
console.log('stuff');
|
package/examples/defaults
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
function list(val) {
|
|
10
|
-
return val.split(',').map(Number);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
program
|
|
14
|
-
.version('0.0.1')
|
|
15
|
-
.option('-t, --template-engine [engine]', 'Add template [engine] support', 'jade')
|
|
16
|
-
.option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')
|
|
17
|
-
.option('-l, --list [items]', 'Specify list items defaulting to 1,2,3', list, [1,2,3])
|
|
18
|
-
.parse(process.argv);
|
|
19
|
-
|
|
20
|
-
console.log(' - %s template engine', program.templateEngine);
|
|
21
|
-
console.log(' - %s cheese', program.cheese);
|
|
22
|
-
console.log(' - %j', program.list);
|
package/examples/deploy
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.version('0.0.1')
|
|
11
|
-
.option('-C, --chdir <path>', 'change the working directory')
|
|
12
|
-
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
|
13
|
-
.option('-T, --no-tests', 'ignore test hook')
|
|
14
|
-
|
|
15
|
-
program
|
|
16
|
-
.command('setup [env]')
|
|
17
|
-
.description('run setup commands for all envs')
|
|
18
|
-
.action(function(env){
|
|
19
|
-
env = env || 'all';
|
|
20
|
-
console.log('setup for %s env(s)', env);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
program
|
|
24
|
-
.command('exec <cmd>')
|
|
25
|
-
.description('execute the given remote cmd')
|
|
26
|
-
.action(function(cmd){
|
|
27
|
-
console.log('exec "%s"', cmd);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
program
|
|
31
|
-
.command('*')
|
|
32
|
-
.action(function(env){
|
|
33
|
-
console.log('deploying "%s"', env);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
program.parse(process.argv);
|
|
37
|
-
|
|
38
|
-
|
package/examples/express
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.version('0.0.1')
|
|
11
|
-
.option('-s, --sessions', 'add session support')
|
|
12
|
-
.option('-t, --template <engine>', 'specify template engine (jade|ejs) [jade]', 'jade')
|
|
13
|
-
.option('-c, --css <engine>', 'specify stylesheet engine (stylus|sass|less) [css]', 'css')
|
|
14
|
-
.parse(process.argv);
|
|
15
|
-
|
|
16
|
-
console.log(' - sessions %j', program.sessions);
|
|
17
|
-
console.log(' - template %j', program.template);
|
|
18
|
-
console.log(' - css %j', program.css);
|
package/examples/input
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
program.prompt('Username: ', function(name){
|
|
10
|
-
console.log('hi %s\n', name);
|
|
11
|
-
|
|
12
|
-
program.prompt('Description:', function(desc){
|
|
13
|
-
console.log('description was "%s"', desc.trim());
|
|
14
|
-
|
|
15
|
-
program.prompt('Age: ', Number, function(age){
|
|
16
|
-
console.log('age: %j\n', age);
|
|
17
|
-
|
|
18
|
-
program.prompt('Birthdate: ', Date, function(date){
|
|
19
|
-
console.log('date: %s\n', date);
|
|
20
|
-
process.stdin.destroy();
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
package/examples/password
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
program.password('Password: ', function(pass){
|
|
10
|
-
console.log('got "%s"', pass);
|
|
11
|
-
program.password('Password: ', '*', function(pass){
|
|
12
|
-
console.log('got "%s"', pass);
|
|
13
|
-
program.password('Password: ', '-', function(pass){
|
|
14
|
-
console.log('got "%s"', pass);
|
|
15
|
-
process.stdin.destroy();
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
});
|
package/examples/pizza
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Module dependencies.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
var program = require('../');
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.version('0.0.1')
|
|
11
|
-
.option('-p, --peppers', 'Add peppers')
|
|
12
|
-
.option('-P, --pineapple', 'Add pineapple')
|
|
13
|
-
.option('-b, --bbq', 'Add bbq sauce')
|
|
14
|
-
.option('-c, --cheese <type>', 'Add the specified type of cheese [marble]')
|
|
15
|
-
.option('-C, --no-cheese', 'You do not want any cheese')
|
|
16
|
-
.parse(process.argv);
|
|
17
|
-
|
|
18
|
-
console.log('you ordered a pizza with:');
|
|
19
|
-
if (program.peppers) console.log(' - peppers');
|
|
20
|
-
if (program.pineappe) console.log(' - pineapple');
|
|
21
|
-
if (program.bbq) console.log(' - bbq');
|
|
22
|
-
|
|
23
|
-
var cheese = true === program.cheese
|
|
24
|
-
? 'marble'
|
|
25
|
-
: program.cheese || 'no';
|
|
26
|
-
|
|
27
|
-
console.log(' - %s cheese', cheese);
|
|
28
|
-
console.log(program.args);
|
package/test/run
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
export NODE_ENV=test
|
|
4
|
-
|
|
5
|
-
echo
|
|
6
|
-
for file in $@; do
|
|
7
|
-
printf "\033[90m ${file#test/}\033[0m "
|
|
8
|
-
node $file 2> /tmp/stderr && echo "\033[36m✓\033[0m"
|
|
9
|
-
code=$?
|
|
10
|
-
if test $code -ne 0; then
|
|
11
|
-
echo "\033[31m✖\033[0m"
|
|
12
|
-
cat /tmp/stderr >&2
|
|
13
|
-
exit $code
|
|
14
|
-
fi
|
|
15
|
-
done
|
|
16
|
-
echo
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-f, --foo', 'add some foo')
|
|
11
|
-
.option('-b, --bar', 'add some bar');
|
|
12
|
-
|
|
13
|
-
program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']);
|
|
14
|
-
program.foo.should.be.true;
|
|
15
|
-
should.equal(undefined, program.bar);
|
|
16
|
-
program.args.should.eql(['--bar', 'baz']);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-c, --cheese [type]', 'optionally specify the type of cheese');
|
|
11
|
-
|
|
12
|
-
program.parse(['node', 'test', '--cheese', 'feta']);
|
|
13
|
-
program.cheese.should.equal('feta');
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-c, --cheese [type]', 'optionally specify the type of cheese');
|
|
11
|
-
|
|
12
|
-
program.parse(['node', 'test', '--cheese']);
|
|
13
|
-
program.cheese.should.be.true;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Module dependencies.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
var program = require('../')
|
|
7
|
-
, should = require('should');
|
|
8
|
-
|
|
9
|
-
program
|
|
10
|
-
.version('0.0.1')
|
|
11
|
-
.option('-p, --pepper', 'add pepper')
|
|
12
|
-
.option('-c, --no-cheese', 'remove cheese');
|
|
13
|
-
|
|
14
|
-
program.parse(['node', 'test', '--pepper']);
|
|
15
|
-
program.pepper.should.be.true;
|
|
16
|
-
program.cheese.should.be.true;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-p, --pepper', 'add pepper')
|
|
11
|
-
.option('-c|--no-cheese', 'remove cheese');
|
|
12
|
-
|
|
13
|
-
program.parse(['node', 'test', '--no-cheese']);
|
|
14
|
-
should.equal(undefined, program.pepper);
|
|
15
|
-
program.cheese.should.be.false;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-p, --pepper', 'add pepper')
|
|
11
|
-
.option('-c, --no-cheese', 'remove cheese');
|
|
12
|
-
|
|
13
|
-
program.parse(['node', 'test', '-pc']);
|
|
14
|
-
program.pepper.should.be.true;
|
|
15
|
-
program.cheese.should.be.false;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-p, --pepper', 'add pepper')
|
|
11
|
-
.option('-c, --no-cheese', 'remove cheese');
|
|
12
|
-
|
|
13
|
-
program.parse(['node', 'test', '-p', '-c']);
|
|
14
|
-
program.pepper.should.be.true;
|
|
15
|
-
program.cheese.should.be.false;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
function parseRange(str) {
|
|
9
|
-
return str.split('..').map(Number);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
program
|
|
13
|
-
.version('0.0.1')
|
|
14
|
-
.option('-i, --my-int <n>', 'pass an int', parseInt)
|
|
15
|
-
.option('-n, --my-num <n>', 'pass a number', Number)
|
|
16
|
-
.option('-f, --my-fLOAT <n>', 'pass a float', parseFloat)
|
|
17
|
-
.option('-m, --my-very-long-float <n>', 'pass a float', parseFloat)
|
|
18
|
-
.option('-u, --my-URL-count <n>', 'pass a float', parseFloat)
|
|
19
|
-
.option('-r, --my-long-range <a..b>', 'pass a range', parseRange);
|
|
20
|
-
|
|
21
|
-
program.parse('node test -i 5.5 -f 5.5 -m 6.5 -u 7.5 -n 15.99 -r 1..5'.split(' '));
|
|
22
|
-
program.myInt.should.equal(5);
|
|
23
|
-
program.myNum.should.equal(15.99);
|
|
24
|
-
program.myFLOAT.should.equal(5.5);
|
|
25
|
-
program.myVeryLongFloat.should.equal(6.5);
|
|
26
|
-
program.myURLCount.should.equal(7.5);
|
|
27
|
-
program.myLongRange.should.eql([1,5]);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
function parseRange(str) {
|
|
9
|
-
return str.split('..').map(Number);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
program
|
|
13
|
-
.version('0.0.1')
|
|
14
|
-
.option('-i, --int <n>', 'pass an int', parseInt)
|
|
15
|
-
.option('-n, --num <n>', 'pass a number', Number)
|
|
16
|
-
.option('-f, --float <n>', 'pass a float', parseFloat)
|
|
17
|
-
.option('-r, --range <a..b>', 'pass a range', parseRange);
|
|
18
|
-
|
|
19
|
-
program.parse('node test -i 5.5 -f 5.5 -n 15.99 -r 1..5'.split(' '));
|
|
20
|
-
program.int.should.equal(5);
|
|
21
|
-
program.num.should.equal(15.99);
|
|
22
|
-
program.float.should.equal(5.5);
|
|
23
|
-
program.range.should.eql([1,5]);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-a, --anchovies', 'Add anchovies?')
|
|
11
|
-
.option('-o, --onions', 'Add onions?', true)
|
|
12
|
-
.option('-v, --olives', 'Add olives? Sorry we only have black.', 'black')
|
|
13
|
-
.option('-s, --no-sauce', 'Uh… okay')
|
|
14
|
-
.option('-r, --crust <type>', 'What kind of crust would you like?', 'hand-tossed')
|
|
15
|
-
.option('-c, --cheese [type]', 'optionally specify the type of cheese', 'mozzarella');
|
|
16
|
-
|
|
17
|
-
program.parse(['node', 'test', '--anchovies', '--onions', '--olives', '--no-sauce', '--crust', 'thin', '--cheese', 'wensleydale']);
|
|
18
|
-
program.should.have.property('anchovies', true);
|
|
19
|
-
program.should.have.property('onions', true);
|
|
20
|
-
program.should.have.property('olives', 'black');
|
|
21
|
-
program.should.have.property('sauce', false);
|
|
22
|
-
program.should.have.property('crust', 'thin');
|
|
23
|
-
program.should.have.property('cheese', 'wensleydale');
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('-a, --anchovies', 'Add anchovies?')
|
|
11
|
-
.option('-o, --onions', 'Add onions?', true)
|
|
12
|
-
.option('-v, --olives', 'Add olives? Sorry we only have black.', 'black')
|
|
13
|
-
.option('-s, --no-sauce', 'Uh… okay')
|
|
14
|
-
.option('-r, --crust <type>', 'What kind of crust would you like?', 'hand-tossed')
|
|
15
|
-
.option('-c, --cheese [type]', 'optionally specify the type of cheese', 'mozzarella');
|
|
16
|
-
|
|
17
|
-
program.parse(['node', 'test']);
|
|
18
|
-
program.should.not.have.property('anchovies');
|
|
19
|
-
program.should.not.have.property('onions');
|
|
20
|
-
program.should.not.have.property('olives');
|
|
21
|
-
program.should.have.property('sauce', true);
|
|
22
|
-
program.should.have.property('crust', 'hand-tossed');
|
|
23
|
-
program.should.have.property('cheese', 'mozzarella');
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var program = require('../')
|
|
6
|
-
, should = require('should');
|
|
7
|
-
|
|
8
|
-
program
|
|
9
|
-
.version('0.0.1')
|
|
10
|
-
.option('--longflag [value]', 'A long only flag with a value');
|
|
11
|
-
|
|
12
|
-
program.parse(['node', 'test', '--longflag', 'something']);
|
|
13
|
-
program.longflag.should.equal('something');
|