commander 0.5.1 → 1.0.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/History.md +19 -0
- package/Readme.md +2 -3
- package/lib/commander.js +50 -11
- 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/test/test.prompt.js +0 -121
package/History.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
|
|
2
|
+
1.0.0 / 2012-07-05
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* add support for optional option descriptions
|
|
6
|
+
* add defaulting of `.version()` to package.json's version
|
|
7
|
+
|
|
8
|
+
0.6.1 / 2012-06-01
|
|
9
|
+
==================
|
|
10
|
+
|
|
11
|
+
* Added: append (yes or no) on confirmation
|
|
12
|
+
* Added: allow node.js v0.7.x
|
|
13
|
+
|
|
14
|
+
0.6.0 / 2012-04-10
|
|
15
|
+
==================
|
|
16
|
+
|
|
17
|
+
* Added `.prompt(obj, callback)` support. Closes #49
|
|
18
|
+
* Added default support to .choose(). Closes #41
|
|
19
|
+
* Fixed the choice example
|
|
20
|
+
|
|
2
21
|
0.5.1 / 2011-12-20
|
|
3
22
|
==================
|
|
4
23
|
|
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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/*!
|
|
3
2
|
* commander
|
|
4
3
|
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
|
@@ -48,7 +47,7 @@ function Option(flags, description) {
|
|
|
48
47
|
flags = flags.split(/[ ,|]+/);
|
|
49
48
|
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();
|
|
50
49
|
this.long = flags.shift();
|
|
51
|
-
this.description = description;
|
|
50
|
+
this.description = description || '';
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
/**
|
|
@@ -342,7 +341,12 @@ Command.prototype.parse = function(argv){
|
|
|
342
341
|
|
|
343
342
|
// guess name
|
|
344
343
|
if (!this.name) this.name = basename(argv[1]);
|
|
345
|
-
|
|
344
|
+
// guess version
|
|
345
|
+
if (!this._version) {
|
|
346
|
+
try {
|
|
347
|
+
this.version(require('../package.json').version);
|
|
348
|
+
} catch(e) {}
|
|
349
|
+
}
|
|
346
350
|
// process argv
|
|
347
351
|
var parsed = this.parseOptions(this.normalize(argv.slice(2)));
|
|
348
352
|
this.args = parsed.args;
|
|
@@ -556,6 +560,7 @@ Command.prototype.unknownOption = function(flag){
|
|
|
556
560
|
process.exit(1);
|
|
557
561
|
};
|
|
558
562
|
|
|
563
|
+
|
|
559
564
|
/**
|
|
560
565
|
* Set the program version to `str`.
|
|
561
566
|
*
|
|
@@ -798,14 +803,34 @@ Command.prototype.promptMultiLine = function(str, fn){
|
|
|
798
803
|
* console.log('description was "%s"', desc.trim());
|
|
799
804
|
* });
|
|
800
805
|
*
|
|
801
|
-
* @param {String} str
|
|
806
|
+
* @param {String|Object} str
|
|
802
807
|
* @param {Function} fn
|
|
803
808
|
* @api public
|
|
804
809
|
*/
|
|
805
810
|
|
|
806
811
|
Command.prototype.prompt = function(str, fn){
|
|
807
|
-
|
|
808
|
-
|
|
812
|
+
var self = this;
|
|
813
|
+
|
|
814
|
+
if ('string' == typeof str) {
|
|
815
|
+
if (/ $/.test(str)) return this.promptSingleLine.apply(this, arguments);
|
|
816
|
+
this.promptMultiLine(str, fn);
|
|
817
|
+
} else {
|
|
818
|
+
var keys = Object.keys(str)
|
|
819
|
+
, obj = {};
|
|
820
|
+
|
|
821
|
+
function next() {
|
|
822
|
+
var key = keys.shift()
|
|
823
|
+
, label = str[key];
|
|
824
|
+
|
|
825
|
+
if (!key) return fn(obj);
|
|
826
|
+
self.prompt(label, function(val){
|
|
827
|
+
obj[key] = val;
|
|
828
|
+
next();
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
next();
|
|
833
|
+
}
|
|
809
834
|
};
|
|
810
835
|
|
|
811
836
|
/**
|
|
@@ -883,11 +908,12 @@ Command.prototype.password = function(str, mask, fn){
|
|
|
883
908
|
*/
|
|
884
909
|
|
|
885
910
|
|
|
886
|
-
Command.prototype.confirm = function(str, fn){
|
|
911
|
+
Command.prototype.confirm = function(str, fn, verbose){
|
|
887
912
|
var self = this;
|
|
888
913
|
this.prompt(str, function(ok){
|
|
889
914
|
if (!ok.trim()) {
|
|
890
|
-
|
|
915
|
+
if (!verbose) str += '(yes or no) ';
|
|
916
|
+
return self.confirm(str, fn, true);
|
|
891
917
|
}
|
|
892
918
|
fn(parseBool(ok));
|
|
893
919
|
});
|
|
@@ -907,20 +933,33 @@ Command.prototype.confirm = function(str, fn){
|
|
|
907
933
|
* });
|
|
908
934
|
*
|
|
909
935
|
* @param {Array} list
|
|
936
|
+
* @param {Number|Function} index or fn
|
|
910
937
|
* @param {Function} fn
|
|
911
938
|
* @api public
|
|
912
939
|
*/
|
|
913
940
|
|
|
914
|
-
Command.prototype.choose = function(list, fn){
|
|
915
|
-
var self = this
|
|
941
|
+
Command.prototype.choose = function(list, index, fn){
|
|
942
|
+
var self = this
|
|
943
|
+
, hasDefault = 'number' == typeof index;
|
|
944
|
+
|
|
945
|
+
if (!hasDefault) {
|
|
946
|
+
fn = index;
|
|
947
|
+
index = null;
|
|
948
|
+
}
|
|
916
949
|
|
|
917
950
|
list.forEach(function(item, i){
|
|
918
|
-
|
|
951
|
+
if (hasDefault && i == index) {
|
|
952
|
+
console.log('* %d) %s', i + 1, item);
|
|
953
|
+
} else {
|
|
954
|
+
console.log(' %d) %s', i + 1, item);
|
|
955
|
+
}
|
|
919
956
|
});
|
|
920
957
|
|
|
921
958
|
function again() {
|
|
922
959
|
self.prompt(' : ', function(val){
|
|
923
960
|
val = parseInt(val, 10) - 1;
|
|
961
|
+
if (hasDefault && isNaN(val)) val = index;
|
|
962
|
+
|
|
924
963
|
if (null == list[val]) {
|
|
925
964
|
again();
|
|
926
965
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander"
|
|
3
|
-
, "version": "0.
|
|
3
|
+
, "version": "1.0.0"
|
|
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');
|
package/test/test.prompt.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
var events = require('events')
|
|
6
|
-
, program = require('../')
|
|
7
|
-
, should = require('should');
|
|
8
|
-
|
|
9
|
-
//mock stdin on process
|
|
10
|
-
var stdin = new events.EventEmitter();
|
|
11
|
-
stdin.setEncoding = stdin.resume = function() {};
|
|
12
|
-
stdin.write = function(data) { stdin.emit('data', data); };
|
|
13
|
-
process.__defineGetter__('stdin', function() { return stdin });
|
|
14
|
-
|
|
15
|
-
//mock stdout on process
|
|
16
|
-
var stdout = new events.EventEmitter();
|
|
17
|
-
stdout.write = function(data) { this.emit('data', data) };
|
|
18
|
-
stdout.expect = function(expected, fn) {
|
|
19
|
-
var actual = '';
|
|
20
|
-
this.once('data', function(data){ actual = data; });
|
|
21
|
-
fn();
|
|
22
|
-
actual.should.equal(expected);
|
|
23
|
-
}
|
|
24
|
-
//var realOut = process.stdout;
|
|
25
|
-
process.__defineGetter__('stdout', function() { return stdout });
|
|
26
|
-
|
|
27
|
-
var count = 0;
|
|
28
|
-
var test = function(expected) {
|
|
29
|
-
count++;
|
|
30
|
-
return function(actual) {
|
|
31
|
-
count--;
|
|
32
|
-
if(expected instanceof Date) {
|
|
33
|
-
//need something better :(
|
|
34
|
-
//using `new Date(date.toString())` round trip
|
|
35
|
-
//loosing some precision for .getTime()
|
|
36
|
-
actual.should.be.an.instanceof(Date);
|
|
37
|
-
} else {
|
|
38
|
-
actual.should.equal(expected);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
process.on('exit', function(){
|
|
44
|
-
count.should.equal(0);
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
/* Single Line String Prompt Tests */
|
|
48
|
-
var prompt = 'hello '
|
|
49
|
-
, expected = 'world';
|
|
50
|
-
|
|
51
|
-
// simple single line string
|
|
52
|
-
stdout.expect(prompt, function(){
|
|
53
|
-
program.prompt(prompt, test(expected));
|
|
54
|
-
stdin.write(expected);
|
|
55
|
-
})
|
|
56
|
-
// with trim
|
|
57
|
-
stdout.expect(prompt, function(){
|
|
58
|
-
program.prompt(prompt, test(expected));
|
|
59
|
-
stdin.write(' ' + expected + ' ');
|
|
60
|
-
})
|
|
61
|
-
// newline
|
|
62
|
-
stdout.expect(prompt, function(){
|
|
63
|
-
program.prompt(prompt, test(''));
|
|
64
|
-
stdin.write('\n');
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
/* Multiline Tests*/
|
|
68
|
-
var prompt = 'A multiline';
|
|
69
|
-
stdout.expect(prompt + '\n', function() {
|
|
70
|
-
program.prompt(prompt, test('hello world\n and what a world\nit could be'));
|
|
71
|
-
stdin.write('hello world\n');
|
|
72
|
-
stdin.write(' and what a world\n');
|
|
73
|
-
stdin.write('it could be\n');
|
|
74
|
-
stdin.write('\n');
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
/* Date Prompt Tests */
|
|
78
|
-
var prompt = 'A date '
|
|
79
|
-
, expected = new Date();
|
|
80
|
-
|
|
81
|
-
// simple date
|
|
82
|
-
stdout.expect(prompt, function(){
|
|
83
|
-
program.prompt(prompt, Date, test(expected));
|
|
84
|
-
stdin.write(expected.toString());
|
|
85
|
-
})
|
|
86
|
-
// not a date twice
|
|
87
|
-
stdout.expect(prompt, function() {
|
|
88
|
-
program.prompt(prompt, Date, test(expected));
|
|
89
|
-
|
|
90
|
-
stdout.expect(prompt + '(must be a date) ', function() {
|
|
91
|
-
stdin.write('blue');
|
|
92
|
-
})
|
|
93
|
-
stdout.expect(prompt + '(must be a date) ', function() {
|
|
94
|
-
stdin.write('blue');
|
|
95
|
-
})
|
|
96
|
-
stdin.write(expected.toString());
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
/* Number Prompt Tests*/
|
|
100
|
-
var prompt = 'A number '
|
|
101
|
-
, expected = 12;
|
|
102
|
-
|
|
103
|
-
//simple number
|
|
104
|
-
stdout.expect(prompt, function(){
|
|
105
|
-
program.prompt(prompt, Number, test(expected));
|
|
106
|
-
stdin.write(expected.toString());
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
// not a number twice
|
|
110
|
-
stdout.expect(prompt, function() {
|
|
111
|
-
program.prompt(prompt, Number, test(expected));
|
|
112
|
-
|
|
113
|
-
stdout.expect(prompt + '(must be a number) ', function() {
|
|
114
|
-
stdin.write('blue');
|
|
115
|
-
})
|
|
116
|
-
stdout.expect(prompt + '(must be a number) ', function() {
|
|
117
|
-
stdin.write('blue');
|
|
118
|
-
})
|
|
119
|
-
stdin.write(expected.toString());
|
|
120
|
-
})
|
|
121
|
-
|