Skip to content

Commit

Permalink
Rename function for make opts/args array-value: push() -> arr().
Browse files Browse the repository at this point in the history
  • Loading branch information
veged committed Aug 30, 2011
1 parent 966742b commit abf9140
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Set a type of option. Mainly using with Boolean for options without value.<br>
**@param** *Object* `_type`<br>
**@returns** *COA.Opt* `this` instance (for chainability)

#### Opt.push
#### Opt.arr
Makes an option accepts multiple values.<br>
Otherwise, the value will be used by the latter passed.<br>
**@returns** *COA.Opt* `this` instance (for chainability)
Expand Down Expand Up @@ -208,7 +208,7 @@ Set a long description for argument to be used anywhere in text messages.<br>
**@param** *String* `_title` argument title<br>
**@returns** *COA.Arg* `this` instance (for chainability)

#### Arg.push
#### Arg.arr
Makes an argument accepts multiple values.<br>
Otherwise, the value will be used by the latter passed.<br>
**@returns** *COA.Arg* `this` instance (for chainability)
Expand Down
2 changes: 1 addition & 1 deletion lib/arg.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports.Arg = Arg = (function() {
Otherwise, the value will be used by the latter passed.
@returns {COA.Arg} this instance (for chainability)
*/
Arg.prototype.push = Opt.prototype.push;
Arg.prototype.arr = Opt.prototype.arr;
/**
Makes an argument required.
@returns {COA.Arg} this instance (for chainability)
Expand Down
4 changes: 2 additions & 2 deletions lib/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ exports.Cmd = Cmd = (function() {
Cmd.prototype._ejectOpt = function(opts, opt) {
var pos;
if ((pos = opts.indexOf(opt)) >= 0) {
if (opts[pos]._push) {
if (opts[pos]._arr) {
return opts[pos];
} else {
return opts.splice(pos, 1)[0];
Expand Down Expand Up @@ -218,7 +218,7 @@ exports.Cmd = Cmd = (function() {
}
} else {
if (arg = (nonParsedArgs || (nonParsedArgs = this._args.concat())).shift()) {
if (arg._push) {
if (arg._arr) {
nonParsedArgs.unshift(arg);
}
arg._parse(i, args);
Expand Down
6 changes: 3 additions & 3 deletions lib/opt.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ exports.Opt = Opt = (function() {
Otherwise, the value will be used by the latter passed.
@returns {COA.Opt} this instance (for chainability)
*/
Opt.prototype.push = function() {
this._push = true;
Opt.prototype.arr = function() {
this._arr = true;
return this;
};
/**
Expand Down Expand Up @@ -144,7 +144,7 @@ exports.Opt = Opt = (function() {
if (this._validate) {
val = this._validate(val);
}
if (this._push) {
if (this._arr) {
(opts[_name = this._name] || (opts[_name] = [])).push(val);
} else {
opts[this._name] = val;
Expand Down
2 changes: 1 addition & 1 deletion src/arg.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports.Arg = class Arg
Otherwise, the value will be used by the latter passed.
@returns {COA.Arg} this instance (for chainability)
###
push: Opt::push
arr: Opt::arr

###*
Makes an argument required.
Expand Down
4 changes: 2 additions & 2 deletions src/cmd.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ exports.Cmd = class Cmd

_ejectOpt: (opts, opt) ->
if (pos = opts.indexOf(opt)) >= 0
if opts[pos]._push
if opts[pos]._arr
opts[pos]
else
opts.splice(pos, 1)[0]
Expand Down Expand Up @@ -216,7 +216,7 @@ exports.Cmd = class Cmd
# arg
else
if arg = (nonParsedArgs or= @_args.concat()).shift()
if arg._push then nonParsedArgs.unshift arg
if arg._arr then nonParsedArgs.unshift arg
arg._parse i, args
else
@errorExit 'Unknown argument', i
Expand Down
6 changes: 3 additions & 3 deletions src/opt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ exports.Opt = class Opt
Otherwise, the value will be used by the latter passed.
@returns {COA.Opt} this instance (for chainability)
###
push: ->
@_push = true
arr: ->
@_arr = true
@

###*
Expand Down Expand Up @@ -124,7 +124,7 @@ exports.Opt = class Opt

_saveVal: (opts, val) ->
if @_validate then val = @_validate val
if @_push
if @_arr
(opts[@_name] or= []).push val
else
opts[@_name] = val
Expand Down
13 changes: 13 additions & 0 deletions tests/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require('../lib/coa').Cmd()
.name('arr')
.title('Array value test')
.helpful()
.opt()
.name('arr').title('Array')
.short('a').long('arr')
.arr()
.act(function(opts) {
console.log(opts.arr);
})
.end()
.parse(['-a', '1', '-a', '2']);

0 comments on commit abf9140

Please sign in to comment.