commander 0.5.0 → 0.6.1
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 +18 -0
- package/Readme.md +2 -3
- package/lib/commander.js +52 -16
- 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 -45
- 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.commands.js +0 -109
- 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,22 @@
|
|
|
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
|
+
|
|
2
20
|
0.5.0 / 2011-12-04
|
|
3
21
|
==================
|
|
4
22
|
|
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
|
@@ -712,9 +712,10 @@ Command.prototype.helpInformation = function(){
|
|
|
712
712
|
*/
|
|
713
713
|
|
|
714
714
|
Command.prototype.promptForNumber = function(str, fn){
|
|
715
|
-
this
|
|
715
|
+
var self = this;
|
|
716
|
+
this.promptSingleLine(str, function parseNumber(val){
|
|
716
717
|
val = Number(val);
|
|
717
|
-
if (isNaN(val)) return
|
|
718
|
+
if (isNaN(val)) return self.promptSingleLine(str + '(must be a number) ', parseNumber);
|
|
718
719
|
fn(val);
|
|
719
720
|
});
|
|
720
721
|
};
|
|
@@ -729,9 +730,9 @@ Command.prototype.promptForNumber = function(str, fn){
|
|
|
729
730
|
|
|
730
731
|
Command.prototype.promptForDate = function(str, fn){
|
|
731
732
|
var self = this;
|
|
732
|
-
this.promptSingleLine(str, function(val){
|
|
733
|
+
this.promptSingleLine(str, function parseDate(val){
|
|
733
734
|
val = new Date(val);
|
|
734
|
-
if (isNaN(val.getTime())) return self.
|
|
735
|
+
if (isNaN(val.getTime())) return self.promptSingleLine(str + '(must be a date) ', parseDate);
|
|
735
736
|
fn(val);
|
|
736
737
|
});
|
|
737
738
|
};
|
|
@@ -765,15 +766,15 @@ Command.prototype.promptSingleLine = function(str, fn){
|
|
|
765
766
|
*/
|
|
766
767
|
|
|
767
768
|
Command.prototype.promptMultiLine = function(str, fn){
|
|
768
|
-
var buf =
|
|
769
|
+
var buf = [];
|
|
769
770
|
console.log(str);
|
|
770
771
|
process.stdin.setEncoding('utf8');
|
|
771
772
|
process.stdin.on('data', function(val){
|
|
772
|
-
if ('\n' == val) {
|
|
773
|
+
if ('\n' == val || '\r\n' == val) {
|
|
773
774
|
process.stdin.removeAllListeners('data');
|
|
774
|
-
fn(buf);
|
|
775
|
+
fn(buf.join('\n'));
|
|
775
776
|
} else {
|
|
776
|
-
buf
|
|
777
|
+
buf.push(val.trimRight());
|
|
777
778
|
}
|
|
778
779
|
}).resume();
|
|
779
780
|
};
|
|
@@ -797,14 +798,34 @@ Command.prototype.promptMultiLine = function(str, fn){
|
|
|
797
798
|
* console.log('description was "%s"', desc.trim());
|
|
798
799
|
* });
|
|
799
800
|
*
|
|
800
|
-
* @param {String} str
|
|
801
|
+
* @param {String|Object} str
|
|
801
802
|
* @param {Function} fn
|
|
802
803
|
* @api public
|
|
803
804
|
*/
|
|
804
805
|
|
|
805
806
|
Command.prototype.prompt = function(str, fn){
|
|
806
|
-
|
|
807
|
-
|
|
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
|
+
}
|
|
808
829
|
};
|
|
809
830
|
|
|
810
831
|
/**
|
|
@@ -841,6 +862,7 @@ Command.prototype.password = function(str, mask, fn){
|
|
|
841
862
|
mask = '';
|
|
842
863
|
}
|
|
843
864
|
|
|
865
|
+
process.stdin.resume();
|
|
844
866
|
tty.setRawMode(true);
|
|
845
867
|
process.stdout.write(str);
|
|
846
868
|
|
|
@@ -881,11 +903,12 @@ Command.prototype.password = function(str, mask, fn){
|
|
|
881
903
|
*/
|
|
882
904
|
|
|
883
905
|
|
|
884
|
-
Command.prototype.confirm = function(str, fn){
|
|
906
|
+
Command.prototype.confirm = function(str, fn, verbose){
|
|
885
907
|
var self = this;
|
|
886
908
|
this.prompt(str, function(ok){
|
|
887
909
|
if (!ok.trim()) {
|
|
888
|
-
|
|
910
|
+
if (!verbose) str += '(yes or no) ';
|
|
911
|
+
return self.confirm(str, fn, true);
|
|
889
912
|
}
|
|
890
913
|
fn(parseBool(ok));
|
|
891
914
|
});
|
|
@@ -905,20 +928,33 @@ Command.prototype.confirm = function(str, fn){
|
|
|
905
928
|
* });
|
|
906
929
|
*
|
|
907
930
|
* @param {Array} list
|
|
931
|
+
* @param {Number|Function} index or fn
|
|
908
932
|
* @param {Function} fn
|
|
909
933
|
* @api public
|
|
910
934
|
*/
|
|
911
935
|
|
|
912
|
-
Command.prototype.choose = function(list, fn){
|
|
913
|
-
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
|
+
}
|
|
914
944
|
|
|
915
945
|
list.forEach(function(item, i){
|
|
916
|
-
|
|
946
|
+
if (hasDefault && i == index) {
|
|
947
|
+
console.log('* %d) %s', i + 1, item);
|
|
948
|
+
} else {
|
|
949
|
+
console.log(' %d) %s', i + 1, item);
|
|
950
|
+
}
|
|
917
951
|
});
|
|
918
952
|
|
|
919
953
|
function again() {
|
|
920
954
|
self.prompt(' : ', function(val){
|
|
921
955
|
val = parseInt(val, 10) - 1;
|
|
956
|
+
if (hasDefault && isNaN(val)) val = index;
|
|
957
|
+
|
|
922
958
|
if (null == list[val]) {
|
|
923
959
|
again();
|
|
924
960
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander"
|
|
3
|
-
, "version": "0.
|
|
3
|
+
, "version": "0.6.1"
|
|
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,45 +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
|
-
.option("-s, --setup_mode [mode]", "Which setup mode to use")
|
|
19
|
-
.action(function(env, options){
|
|
20
|
-
var mode = options.setup_mode || "normal";
|
|
21
|
-
env = env || 'all';
|
|
22
|
-
console.log('setup for %s env(s) with %s mode', env, mode);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
program
|
|
26
|
-
.command('exec <cmd>')
|
|
27
|
-
.description('execute the given remote cmd')
|
|
28
|
-
.option("-e, --exec_mode <mode>", "Which exec mode to use")
|
|
29
|
-
.action(function(cmd, options){
|
|
30
|
-
console.log('exec "%s" using %s mode', cmd, options.exec_mode);
|
|
31
|
-
}).on('--help', function() {
|
|
32
|
-
console.log(' Examples:');
|
|
33
|
-
console.log();
|
|
34
|
-
console.log(' $ deploy exec sequential');
|
|
35
|
-
console.log(' $ deploy exec async');
|
|
36
|
-
console.log();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
program
|
|
40
|
-
.command('*')
|
|
41
|
-
.action(function(env){
|
|
42
|
-
console.log('deploying "%s"', env);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
program.parse(process.argv);
|
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,109 +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, --chdir <path>', 'change the working directory')
|
|
11
|
-
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
|
12
|
-
.option('-T, --no-tests', 'ignore test hook')
|
|
13
|
-
|
|
14
|
-
var envValue = "";
|
|
15
|
-
var cmdValue = "";
|
|
16
|
-
var customHelp = false;
|
|
17
|
-
|
|
18
|
-
program
|
|
19
|
-
.command('setup [env]')
|
|
20
|
-
.description('run setup commands for all envs')
|
|
21
|
-
.option("-s, --setup_mode [mode]", "Which setup mode to use")
|
|
22
|
-
.option("-o, --host [host]", "Host to use")
|
|
23
|
-
.action(function(env, options){
|
|
24
|
-
var mode = options.setup_mode || "normal";
|
|
25
|
-
env = env || 'all';
|
|
26
|
-
|
|
27
|
-
envValue = env;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
program
|
|
31
|
-
.command('exec <cmd>')
|
|
32
|
-
.description('execute the given remote cmd')
|
|
33
|
-
.option("-e, --exec_mode <mode>", "Which exec mode to use")
|
|
34
|
-
.option("-t, --target [target]", "Target to use")
|
|
35
|
-
.action(function(cmd, options){
|
|
36
|
-
cmdValue = cmd;
|
|
37
|
-
}).on("--help", function(){
|
|
38
|
-
customHelp = true;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
program
|
|
42
|
-
.command('*')
|
|
43
|
-
.action(function(env){
|
|
44
|
-
console.log('deploying "%s"', env);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
program.parse(['node', 'test', '--config', 'conf']);
|
|
48
|
-
program.config.should.equal("conf");
|
|
49
|
-
program.commands[0].should.not.have.property.setup_mode;
|
|
50
|
-
program.commands[1].should.not.have.property.exec_mode;
|
|
51
|
-
envValue.should.be.null;
|
|
52
|
-
cmdValue.should.be.null;
|
|
53
|
-
|
|
54
|
-
program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode3', 'env1']);
|
|
55
|
-
program.config.should.equal("conf1");
|
|
56
|
-
program.commands[0].setup_mode.should.equal("mode3");
|
|
57
|
-
program.commands[0].should.not.have.property.host;
|
|
58
|
-
envValue.should.equal("env1");
|
|
59
|
-
|
|
60
|
-
program.parse(['node', 'test', '--config', 'conf2', 'setup', '--setup_mode', 'mode3', '-o', 'host1', 'env2']);
|
|
61
|
-
program.config.should.equal("conf2");
|
|
62
|
-
program.commands[0].setup_mode.should.equal("mode3");
|
|
63
|
-
program.commands[0].host.should.equal("host1");
|
|
64
|
-
envValue.should.equal("env2");
|
|
65
|
-
|
|
66
|
-
program.parse(['node', 'test', '--config', 'conf3', 'setup', '-s', 'mode4', 'env3']);
|
|
67
|
-
program.config.should.equal("conf3");
|
|
68
|
-
program.commands[0].setup_mode.should.equal("mode4");
|
|
69
|
-
envValue.should.equal("env3");
|
|
70
|
-
|
|
71
|
-
program.parse(['node', 'test', '--config', 'conf4', 'exec', '--exec_mode', 'mode1', 'exec1']);
|
|
72
|
-
program.config.should.equal("conf4");
|
|
73
|
-
program.commands[1].exec_mode.should.equal("mode1");
|
|
74
|
-
program.commands[1].should.not.have.property.target;
|
|
75
|
-
cmdValue.should.equal("exec1");
|
|
76
|
-
|
|
77
|
-
program.parse(['node', 'test', '--config', 'conf5', 'exec', '-e', 'mode2', 'exec2']);
|
|
78
|
-
program.config.should.equal("conf5");
|
|
79
|
-
program.commands[1].exec_mode.should.equal("mode2");
|
|
80
|
-
cmdValue.should.equal("exec2");
|
|
81
|
-
|
|
82
|
-
program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode2', 'exec3']);
|
|
83
|
-
program.config.should.equal("conf6");
|
|
84
|
-
program.commands[1].exec_mode.should.equal("mode2");
|
|
85
|
-
program.commands[1].target.should.equal("target1");
|
|
86
|
-
cmdValue.should.equal("exec3");
|
|
87
|
-
|
|
88
|
-
// Make sure we still catch errors with required values for options
|
|
89
|
-
var exceptionOccurred = false;
|
|
90
|
-
var oldProcessExit = process.exit;
|
|
91
|
-
var oldConsoleError = console.error;
|
|
92
|
-
process.exit = function() { exceptionOccurred = true; throw new Error(); };
|
|
93
|
-
console.error = function() {};
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
program.parse(['node', 'test', '--config', 'conf6', 'exec', '--help']);
|
|
97
|
-
} catch(ex) {
|
|
98
|
-
program.config.should.equal("conf6");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
program.parse(['node', 'test', '--config', 'conf', 'exec', '-t', 'target1', 'exec1', '-e']);
|
|
103
|
-
}
|
|
104
|
-
catch(ex) {
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
process.exit = oldProcessExit;
|
|
108
|
-
exceptionOccurred.should.be.true;
|
|
109
|
-
customHelp.should.be.true;
|
|
@@ -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');
|