Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename function for make options without value: type(Boolean) -> flag…

…(). It used only for Boolean type, any other type checks should be done by validation function.
  • Loading branch information...
commit 48d2955372a82ec24aaf03ee98954d852f2be131 1 parent abf9140
Sergey Berezhnoy authored
5 README.md
View
@@ -145,9 +145,8 @@ Set a short key for option to be used with double hyphens from command line.<br>
**@param** *String* `_long`<br>
**@returns** *COA.Opt* `this` instance (for chainability)
-#### Opt.type
-Set a type of option. Mainly using with Boolean for options without value.<br>
-**@param** *Object* `_type`<br>
+#### Opt.flag
+Make an option boolean, i.e. option without value.<br>
**@returns** *COA.Opt* `this` instance (for chainability)
#### Opt.arr
2  lib/cmd.js
View
@@ -110,7 +110,7 @@ exports.Cmd = Cmd = (function() {
*/
Cmd.prototype.helpful = function() {
this._helpful = true;
- return this.opt().name('help').title('Help').short('h').long('help').type(Boolean).act(function(opts, args) {
+ return this.opt().name('help').title('Help').short('h').long('help').flag().act(function(opts, args) {
return this.exit(this.usage());
}).end();
};
8 lib/opt.js
View
@@ -50,13 +50,11 @@ exports.Opt = Opt = (function() {
return this._cmd._optsByKey['--' + _long] = this;
};
/**
- Set a type of option. Mainly using with Boolean for options without value.
- @param {Object} _type
+ Make an option boolean, i.e. option without value.
@returns {COA.Opt} this instance (for chainability)
*/
- Opt.prototype.type = function(_type) {
- this._type = _type;
- this._flag = this._type === Boolean;
+ Opt.prototype.flag = function() {
+ this._flag = true;
return this;
};
/**
2  src/cmd.coffee
View
@@ -105,7 +105,7 @@ exports.Cmd = class Cmd
@opt()
.name('help').title('Help')
.short('h').long('help')
- .type(Boolean)
+ .flag()
.act (opts, args) ->
@exit @usage()
.end()
7 src/opt.coffee
View
@@ -45,12 +45,11 @@ exports.Opt = class Opt
long: (@_long) -> @_cmd._optsByKey['--' + _long] = @
###*
- Set a type of option. Mainly using with Boolean for options without value.
- @param {Object} _type
+ Make an option boolean, i.e. option without value.
@returns {COA.Opt} this instance (for chainability)
###
- type: (@_type) ->
- @_flag = @_type is Boolean
+ flag: () ->
+ @_flag = true
@
###*
2  tests/v.js
View
@@ -5,7 +5,7 @@ require('../lib/coa').Cmd()
.opt()
.name('version').title('Version')
.short('v').long('version')
- .type(Boolean)
+ .flag()
.act(function(opts) {
this.exit(
JSON.parse(require('fs').readFileSync(__dirname + '/../package.json'))
Please sign in to comment.
Something went wrong with that request. Please try again.