commander 1.1.1 → 1.2.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 CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ 1.2.0 / 2013-06-13
3
+ ==================
4
+
5
+ * allow "-" hyphen as an option argument
6
+ * support for RegExp coercion
7
+
2
8
  1.1.1 / 2012-11-20
3
9
  ==================
4
10
 
package/Readme.md CHANGED
@@ -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:
package/index.js CHANGED
@@ -543,12 +543,12 @@ Command.prototype.parseOptions = function(argv){
543
543
  if (option.required) {
544
544
  arg = argv[++i];
545
545
  if (null == arg) return this.optionMissingArgument(option);
546
- if ('-' == arg[0]) return this.optionMissingArgument(option, arg);
546
+ if ('-' == arg[0] && '-' != arg) return this.optionMissingArgument(option, arg);
547
547
  this.emit(option.name(), arg);
548
548
  // optional arg
549
549
  } else if (option.optional) {
550
550
  arg = argv[i+1];
551
- if (null == arg || '-' == arg[0]) {
551
+ if (null == arg || ('-' == arg[0] && '-' != arg)) {
552
552
  arg = null;
553
553
  } else {
554
554
  ++i;
@@ -811,6 +811,25 @@ Command.prototype.promptForDate = function(str, fn){
811
811
  });
812
812
  };
813
813
 
814
+
815
+ /**
816
+ * Prompt for a `Regular Expression`.
817
+ *
818
+ * @param {String} str
819
+ * @param {Object} pattern regular expression object to test
820
+ * @param {Function} fn
821
+ * @api private
822
+ */
823
+
824
+ Command.prototype.promptForRegexp = function(str, pattern, fn){
825
+ var self = this;
826
+ this.promptSingleLine(str, function parseRegexp(val){
827
+ if(!pattern.test(val)) return self.promptSingleLine(str + '(regular expression mismatch) ', parseRegexp);
828
+ fn(val);
829
+ });
830
+ };
831
+
832
+
814
833
  /**
815
834
  * Single-line prompt.
816
835
  *
@@ -820,7 +839,10 @@ Command.prototype.promptForDate = function(str, fn){
820
839
  */
821
840
 
822
841
  Command.prototype.promptSingleLine = function(str, fn){
823
- if ('function' == typeof arguments[2]) {
842
+ // determine if the 2nd argument is a regular expression
843
+ if (arguments[1].global !== undefined && arguments[1].multiline !== undefined) {
844
+ return this.promptForRegexp(str, arguments[1], arguments[2]);
845
+ } else if ('function' == typeof arguments[2]) {
824
846
  return this['promptFor' + (fn.name || fn)](str, arguments[2]);
825
847
  }
826
848
 
@@ -879,7 +901,6 @@ Command.prototype.promptMultiLine = function(str, fn){
879
901
 
880
902
  Command.prototype.prompt = function(str, fn){
881
903
  var self = this;
882
-
883
904
  if ('string' == typeof str) {
884
905
  if (/ $/.test(str)) return this.promptSingleLine.apply(this, arguments);
885
906
  this.promptMultiLine(str, fn);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "commander"
3
- , "version": "1.1.1"
3
+ , "version": "1.2.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>"
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
@@ -1,4 +0,0 @@
1
- support
2
- test
3
- examples
4
- *.sock
package/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 0.4
4
- - 0.6
package/Makefile DELETED
@@ -1,7 +0,0 @@
1
-
2
- TESTS = $(shell find test/test.*.js)
3
-
4
- test:
5
- @./test/run $(TESTS)
6
-
7
- .PHONY: test