Skip to content

Commit

Permalink
Rename function for make options without value: type(Boolean) -> flag…
Browse files Browse the repository at this point in the history
…(). It used only for Boolean type, any other type checks should be done by validation function.
  • Loading branch information
veged committed Aug 30, 2011
1 parent abf9140 commit 48d2955
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
8 changes: 3 additions & 5 deletions lib/opt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
/**
Expand Down
2 changes: 1 addition & 1 deletion src/cmd.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions src/opt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
@

###*
Expand Down
2 changes: 1 addition & 1 deletion tests/v.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 48d2955

Please sign in to comment.