commander 1.1.1 → 1.3.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 +22 -0
- package/Readme.md +9 -3
- package/index.js +41 -12
- package/package.json +2 -2
- package/.npmignore +0 -4
- package/.travis.yml +0 -4
- package/Makefile +0 -7
package/History.md
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
|
|
2
|
+
1.3.2 / 2013-07-18
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* add support for sub-commands to co-exist with the original command
|
|
6
|
+
|
|
7
|
+
1.3.1 / 2013-07-18
|
|
8
|
+
==================
|
|
9
|
+
|
|
10
|
+
* add quick .runningCommand hack so you can opt-out of other logic when running a sub command
|
|
11
|
+
|
|
12
|
+
1.3.0 / 2013-07-09
|
|
13
|
+
==================
|
|
14
|
+
|
|
15
|
+
* add EACCES error handling
|
|
16
|
+
* fix sub-command --help
|
|
17
|
+
|
|
18
|
+
1.2.0 / 2013-06-13
|
|
19
|
+
==================
|
|
20
|
+
|
|
21
|
+
* allow "-" hyphen as an option argument
|
|
22
|
+
* support for RegExp coercion
|
|
23
|
+
|
|
2
24
|
1.1.1 / 2012-11-20
|
|
3
25
|
==================
|
|
4
26
|
|
package/Readme.md
CHANGED
|
@@ -31,7 +31,7 @@ program
|
|
|
31
31
|
|
|
32
32
|
console.log('you ordered a pizza with:');
|
|
33
33
|
if (program.peppers) console.log(' - peppers');
|
|
34
|
-
if (program.pineapple) console.log(' -
|
|
34
|
+
if (program.pineapple) console.log(' - pineapple');
|
|
35
35
|
if (program.bbq) console.log(' - bbq');
|
|
36
36
|
console.log(' - %s cheese', program.cheese);
|
|
37
37
|
```
|
|
@@ -51,7 +51,7 @@ console.log(' - %s cheese', program.cheese);
|
|
|
51
51
|
|
|
52
52
|
-V, --version output the version number
|
|
53
53
|
-p, --peppers Add peppers
|
|
54
|
-
-P, --pineapple Add
|
|
54
|
+
-P, --pineapple Add pineapple
|
|
55
55
|
-b, --bbq Add bbq sauce
|
|
56
56
|
-c, --cheese <type> Add the specified type of cheese [marble]
|
|
57
57
|
-h, --help output usage information
|
|
@@ -185,6 +185,12 @@ program.prompt('Birthdate: ', Date, function(date){
|
|
|
185
185
|
});
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
+
```js
|
|
189
|
+
program.prompt('Email: ', /^.+@.+\..+$/, function(email){
|
|
190
|
+
console.log('email: %j', email);
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
188
194
|
## .password(msg[, mask], fn)
|
|
189
195
|
|
|
190
196
|
Prompt for password without echoing:
|
|
@@ -267,4 +273,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
267
273
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
268
274
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
269
275
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
270
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
276
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/index.js
CHANGED
|
@@ -91,6 +91,7 @@ Option.prototype.is = function(arg){
|
|
|
91
91
|
function Command(name) {
|
|
92
92
|
this.commands = [];
|
|
93
93
|
this.options = [];
|
|
94
|
+
this._execs = [];
|
|
94
95
|
this._args = [];
|
|
95
96
|
this._name = name;
|
|
96
97
|
}
|
|
@@ -155,6 +156,7 @@ Command.prototype.command = function(name, desc){
|
|
|
155
156
|
var cmd = new Command(args.shift());
|
|
156
157
|
if (desc) cmd.description(desc);
|
|
157
158
|
if (desc) this.executables = true;
|
|
159
|
+
if (desc) this._execs[cmd._name] = true;
|
|
158
160
|
this.commands.push(cmd);
|
|
159
161
|
cmd.parseExpectedArgs(args);
|
|
160
162
|
cmd.parent = this;
|
|
@@ -372,10 +374,13 @@ Command.prototype.parse = function(argv){
|
|
|
372
374
|
var parsed = this.parseOptions(this.normalize(argv.slice(2)));
|
|
373
375
|
var args = this.args = parsed.args;
|
|
374
376
|
|
|
375
|
-
|
|
376
|
-
if (this.executables) return this.executeSubCommand(argv, args, parsed.unknown);
|
|
377
|
+
var result = this.parseArgs(this.args, parsed.unknown);
|
|
377
378
|
|
|
378
|
-
|
|
379
|
+
// executable sub-commands
|
|
380
|
+
var name = result.args[0];
|
|
381
|
+
if (this._execs[name]) return this.executeSubCommand(argv, args, parsed.unknown);
|
|
382
|
+
|
|
383
|
+
return result;
|
|
379
384
|
};
|
|
380
385
|
|
|
381
386
|
/**
|
|
@@ -405,16 +410,19 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
405
410
|
|
|
406
411
|
// check for ./<bin> first
|
|
407
412
|
var local = path.join(dir, bin);
|
|
408
|
-
if (exists(local)) bin = local;
|
|
409
413
|
|
|
410
414
|
// run it
|
|
411
415
|
args = args.slice(1);
|
|
412
|
-
var proc = spawn(
|
|
413
|
-
proc.on('
|
|
414
|
-
if (code ==
|
|
415
|
-
console.error('\n %s(1) does not exist\n', bin);
|
|
416
|
+
var proc = spawn(local, args, { stdio: 'inherit', customFds: [0, 1, 2] });
|
|
417
|
+
proc.on('error', function(err){
|
|
418
|
+
if (err.code == "ENOENT") {
|
|
419
|
+
console.error('\n %s(1) does not exist, try --help\n', bin);
|
|
420
|
+
} else if (err.code == "EACCES") {
|
|
421
|
+
console.error('\n %s(1) not executable. try chmod or run with root\n', bin);
|
|
416
422
|
}
|
|
417
423
|
});
|
|
424
|
+
|
|
425
|
+
this.runningCommand = proc;
|
|
418
426
|
};
|
|
419
427
|
|
|
420
428
|
/**
|
|
@@ -543,12 +551,12 @@ Command.prototype.parseOptions = function(argv){
|
|
|
543
551
|
if (option.required) {
|
|
544
552
|
arg = argv[++i];
|
|
545
553
|
if (null == arg) return this.optionMissingArgument(option);
|
|
546
|
-
if ('-' == arg[0]) return this.optionMissingArgument(option, arg);
|
|
554
|
+
if ('-' == arg[0] && '-' != arg) return this.optionMissingArgument(option, arg);
|
|
547
555
|
this.emit(option.name(), arg);
|
|
548
556
|
// optional arg
|
|
549
557
|
} else if (option.optional) {
|
|
550
558
|
arg = argv[i+1];
|
|
551
|
-
if (null == arg || '-' == arg[0]) {
|
|
559
|
+
if (null == arg || ('-' == arg[0] && '-' != arg)) {
|
|
552
560
|
arg = null;
|
|
553
561
|
} else {
|
|
554
562
|
++i;
|
|
@@ -811,6 +819,25 @@ Command.prototype.promptForDate = function(str, fn){
|
|
|
811
819
|
});
|
|
812
820
|
};
|
|
813
821
|
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* Prompt for a `Regular Expression`.
|
|
825
|
+
*
|
|
826
|
+
* @param {String} str
|
|
827
|
+
* @param {Object} pattern regular expression object to test
|
|
828
|
+
* @param {Function} fn
|
|
829
|
+
* @api private
|
|
830
|
+
*/
|
|
831
|
+
|
|
832
|
+
Command.prototype.promptForRegexp = function(str, pattern, fn){
|
|
833
|
+
var self = this;
|
|
834
|
+
this.promptSingleLine(str, function parseRegexp(val){
|
|
835
|
+
if(!pattern.test(val)) return self.promptSingleLine(str + '(regular expression mismatch) ', parseRegexp);
|
|
836
|
+
fn(val);
|
|
837
|
+
});
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
|
|
814
841
|
/**
|
|
815
842
|
* Single-line prompt.
|
|
816
843
|
*
|
|
@@ -820,7 +847,10 @@ Command.prototype.promptForDate = function(str, fn){
|
|
|
820
847
|
*/
|
|
821
848
|
|
|
822
849
|
Command.prototype.promptSingleLine = function(str, fn){
|
|
823
|
-
if
|
|
850
|
+
// determine if the 2nd argument is a regular expression
|
|
851
|
+
if (arguments[1].global !== undefined && arguments[1].multiline !== undefined) {
|
|
852
|
+
return this.promptForRegexp(str, arguments[1], arguments[2]);
|
|
853
|
+
} else if ('function' == typeof arguments[2]) {
|
|
824
854
|
return this['promptFor' + (fn.name || fn)](str, arguments[2]);
|
|
825
855
|
}
|
|
826
856
|
|
|
@@ -879,7 +909,6 @@ Command.prototype.promptMultiLine = function(str, fn){
|
|
|
879
909
|
|
|
880
910
|
Command.prototype.prompt = function(str, fn){
|
|
881
911
|
var self = this;
|
|
882
|
-
|
|
883
912
|
if ('string' == typeof str) {
|
|
884
913
|
if (/ $/.test(str)) return this.promptSingleLine.apply(this, arguments);
|
|
885
914
|
this.promptMultiLine(str, fn);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander"
|
|
3
|
-
, "version": "1.
|
|
3
|
+
, "version": "1.3.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>"
|
|
7
|
-
, "repository": { "type": "git", "url": "https://github.com/visionmedia/commander.js.git" }
|
|
7
|
+
, "repository": { "type": "git", "url": "https://github.com/visionmedia/commander.js.git" }
|
|
8
8
|
, "dependencies": { "keypress": "0.1.x"}
|
|
9
9
|
, "devDependencies": { "should": ">= 0.0.1" }
|
|
10
10
|
, "scripts": { "test": "make test" }
|
package/.npmignore
DELETED
package/.travis.yml
DELETED