Comparing version 0.0.4 to 0.0.5
@@ -36,3 +36,3 @@ var Arg, Cmd, Color, Opt; | ||
*/ | ||
Arg.prototype.push = Opt.prototype.push; | ||
Arg.prototype.arr = Opt.prototype.arr; | ||
/** | ||
@@ -42,7 +42,8 @@ Makes an argument required. | ||
*/ | ||
Arg.prototype.required = Opt.prototype.required; | ||
Arg.prototype.req = Opt.prototype.req; | ||
/** | ||
Set a validation function for argument. | ||
Set a validation (or value) function for argument. | ||
Value from command line passes through before becoming available from API. | ||
@param {Function} _validate validating function, | ||
Using for validation and convertion simple types to any values. | ||
@param {Function} _val validating function, | ||
invoked in the context of argument instance | ||
@@ -52,3 +53,3 @@ and has one parameter with value from command line | ||
*/ | ||
Arg.prototype.validate = Opt.prototype.validate; | ||
Arg.prototype.val = Opt.prototype.val; | ||
/** | ||
@@ -55,0 +56,0 @@ Set a default value for argument. |
@@ -1,2 +0,2 @@ | ||
var Cmd, Color, inspect, path, sys; | ||
var Cmd, Color, path, sys; | ||
var __slice = Array.prototype.slice; | ||
@@ -6,6 +6,2 @@ sys = require('sys'); | ||
Color = require('./color').Color; | ||
inspect = require('eyes').inspector({ | ||
maxLength: 99999, | ||
stream: process.stderr | ||
}); | ||
/** | ||
@@ -118,3 +114,3 @@ ## Command | ||
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()); | ||
@@ -188,3 +184,3 @@ }).end(); | ||
if ((pos = opts.indexOf(opt)) >= 0) { | ||
if (opts[pos]._push) { | ||
if (opts[pos]._arr) { | ||
return opts[pos]; | ||
@@ -228,3 +224,3 @@ } else { | ||
if (arg = (nonParsedArgs || (nonParsedArgs = this._args.concat())).shift()) { | ||
if (arg._push) { | ||
if (arg._arr) { | ||
nonParsedArgs.unshift(arg); | ||
@@ -242,3 +238,3 @@ } | ||
while (i = nonParsed.shift()) { | ||
if (i._required && i._checkParsed(opts, args)) { | ||
if (i._req && i._checkParsed(opts, args)) { | ||
this.errorExit(i._requiredText()); | ||
@@ -245,0 +241,0 @@ } |
@@ -53,9 +53,7 @@ var Cmd, Color, Opt, fs; | ||
/** | ||
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; | ||
@@ -68,4 +66,4 @@ }; | ||
*/ | ||
Opt.prototype.push = function() { | ||
this._push = true; | ||
Opt.prototype.arr = function() { | ||
this._arr = true; | ||
return this; | ||
@@ -77,10 +75,11 @@ }; | ||
*/ | ||
Opt.prototype.required = function() { | ||
this._required = true; | ||
Opt.prototype.req = function() { | ||
this._req = true; | ||
return this; | ||
}; | ||
/** | ||
Set a validation function for option. | ||
Set a validation (or value) function for option. | ||
Value from command line passes through before becoming available from API. | ||
@param {Function} _validate validating function, | ||
Using for validation and convertion simple types to any values. | ||
@param {Function} _val validating function, | ||
invoked in the context of option instance | ||
@@ -90,4 +89,4 @@ and has one parameter with value from command line | ||
*/ | ||
Opt.prototype.validate = function(_validate) { | ||
this._validate = _validate; | ||
Opt.prototype.val = function(_val) { | ||
this._val = _val; | ||
return this; | ||
@@ -111,3 +110,3 @@ }; | ||
Opt.prototype.output = function() { | ||
return this.def(process.stdout).validate(function(v) { | ||
return this.def(process.stdout).val(function(v) { | ||
if (typeof v === 'string') { | ||
@@ -149,6 +148,6 @@ if (v === '-') { | ||
var _name; | ||
if (this._validate) { | ||
val = this._validate(val); | ||
if (this._val) { | ||
val = this._val(val); | ||
} | ||
if (this._push) { | ||
if (this._arr) { | ||
(opts[_name = this._name] || (opts[_name] = [])).push(val); | ||
@@ -155,0 +154,0 @@ } else { |
{ | ||
"name" : "coa", | ||
"description" : "Command-Option-Argument: Yet another parser for command line options.", | ||
"version" : "0.0.4", | ||
"version" : "0.0.5", | ||
"homepage" : "http://github.com/veged/coa", | ||
@@ -6,0 +6,0 @@ "author" : { |
@@ -32,5 +32,5 @@ # Command-Option-Argument | ||
.short('i').long('input') | ||
.validate(function(v) { // validator function, also for translate simple values | ||
.val(function(v) { // validator function, also for translate simple values | ||
return require('fs').createReadStream(v) }) | ||
.required() // make option required | ||
.req() // make option required | ||
.end() // end option chain and return to command | ||
@@ -149,8 +149,7 @@ .end() // end subcommand chain and return to parent command | ||
#### 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.push | ||
#### Opt.arr | ||
Makes an option accepts multiple values.<br> | ||
@@ -160,10 +159,11 @@ Otherwise, the value will be used by the latter passed.<br> | ||
#### Opt.required | ||
Makes an option required.<br> | ||
#### Opt.req | ||
Makes an option req.<br> | ||
**@returns** *COA.Opt* `this` instance (for chainability) | ||
#### Opt.validate | ||
Set a validation function for option.<br> | ||
#### Opt.val | ||
Set a validation (or value) function for argument.<br> | ||
Value from command line passes through before becoming available from API.<br> | ||
**@param** *Function* `_validate` validating function, | ||
Using for validation and convertion simple types to any values.<br> | ||
**@param** *Function* `_val` validating function, | ||
invoked in the context of option instance | ||
@@ -214,3 +214,3 @@ and has one parameter with value from command line<br> | ||
#### Arg.push | ||
#### Arg.arr | ||
Makes an argument accepts multiple values.<br> | ||
@@ -220,10 +220,11 @@ Otherwise, the value will be used by the latter passed.<br> | ||
#### Arg.required | ||
Makes an argument required.<br> | ||
#### Arg.req | ||
Makes an argument req.<br> | ||
**@returns** *COA.Arg* `this` instance (for chainability) | ||
#### Arg.validate | ||
Set a validation function for argument.<br> | ||
#### Arg.val | ||
Set a validation (or value) function for argument.<br> | ||
Value from command line passes through before becoming available from API.<br> | ||
**@param** *Function* `_validate` validating function, | ||
Using for validation and convertion simple types to any values.<br> | ||
**@param** *Function* `_val` validating function, | ||
invoked in the context of argument instance | ||
@@ -230,0 +231,0 @@ and has one parameter with value from command line<br> |
@@ -8,3 +8,3 @@ require('../lib/coa').Cmd() | ||
.short('v').long('version') | ||
.type(Boolean) | ||
.flag() | ||
.act(function(opts) { | ||
@@ -11,0 +11,0 @@ this.exit( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
91833
23
741
253
0