cli-define
Advanced tools
Comparing version
158
index.js
@@ -1,48 +0,14 @@ | ||
var EOL = require('os').EOL; | ||
var events = require('events'); | ||
var fs = require('fs'); | ||
var path = require('path'), basename = path.basename; | ||
var util = require('util'); | ||
var utils = require('cli-util'); | ||
var camelcase = utils.camelcase; | ||
var rtrim = utils.rtrim; | ||
var markzero = require('markzero'); | ||
var marked = markzero.marked; | ||
var Parser = markzero.Parser; | ||
var TextRenderer = markzero.TextRenderer; | ||
var events = require('events') | ||
, path = require('path') | ||
, basename = path.basename | ||
, util = require('util') | ||
, utils = require('cli-util') | ||
, camelcase = utils.camelcase | ||
, define = utils.define | ||
var helpers = require('./lib'); | ||
, EventProxy = require('./lib/event-proxy') | ||
, Description = require('cli-description') | ||
, mutators = require('./lib/mutators') | ||
, helpers = require('./lib/finder'); | ||
var mutators = { | ||
cmd: { | ||
parent: true, | ||
options: false, | ||
commands: false, | ||
sections: true, | ||
names: false, | ||
key: true, | ||
name: true, | ||
extra: true, | ||
options: true, | ||
commands: true, | ||
last: true | ||
}, | ||
arg: { | ||
names: false, | ||
key: true, | ||
name: true, | ||
optional: true, | ||
multiple: true, | ||
value: true, | ||
converter: true, | ||
extra: true, | ||
converter: true, | ||
action: true | ||
}, | ||
prg: { | ||
converter: true, | ||
configure: true, | ||
} | ||
} | ||
var k, keys; | ||
@@ -71,44 +37,2 @@ var re = { | ||
function getNoVariants(arg) { | ||
if(!arg) return null; | ||
var name = (typeof arg === 'string') ? arg : arg.name(); | ||
if(re.no().test(name)) { | ||
var yes = name.replace(re.no(), ''); | ||
var no = name.replace(/^(-+)\[?(no)\]?-?(.*)/, "$1$2-$3"); | ||
return {yes: yes, no: no}; | ||
} | ||
return false; | ||
} | ||
function toDescription(desc) { | ||
if(desc instanceof Description) return desc; | ||
return new Description(desc); | ||
} | ||
var lexer = new markzero.Lexer(); | ||
var renderer = new TextRenderer; | ||
var Description = function(md) { | ||
this.parse(md); | ||
} | ||
Description.prototype.parse = function(md, append) { | ||
if(append && this.md) { | ||
md = this.md = (this.md + md); | ||
}else{ | ||
this.md = '' + md; | ||
} | ||
var tokens = lexer.lex(md); | ||
var parser = new Parser({renderer: renderer}); | ||
this.txt = rtrim(parser.parse(tokens)); | ||
} | ||
Description.prototype.concat = function(md) { | ||
this.parse(md, true); | ||
} | ||
Description.prototype.toString = function() { | ||
return this.txt; | ||
} | ||
function description(description) { | ||
@@ -216,43 +140,17 @@ if(!arguments.length) return this._description; | ||
var EventProxy = { | ||
setMaxListeners: function() { | ||
return this._emitter.setMaxListeners.apply(this, arguments); | ||
}, | ||
emit: function() { | ||
return this._emitter.emit.apply(this, arguments); | ||
}, | ||
addListener: function() { | ||
return this._emitter.addListener.apply(this, arguments); | ||
}, | ||
on: function() { | ||
return this._emitter.on.apply(this, arguments); | ||
}, | ||
once: function() { | ||
return this._emitter.once.apply(this, arguments); | ||
}, | ||
removeListener: function() { | ||
return this._emitter.removeListener.apply(this, arguments); | ||
}, | ||
removeAllListeners: function() { | ||
return this._emitter.removeAllListeners.apply(this, arguments); | ||
}, | ||
listeners: function() { | ||
return this._emitter.listeners.apply(this, arguments); | ||
} | ||
} | ||
//var enumerable = process.env.CLI_TOOLKIT_DEBUG ? true : false; | ||
var enumerable = process.env.CLI_TOOLKIT_DEBUG ? true : false; | ||
//function define(obj, name, value, writable, enumerate) { | ||
//writable = writable !== undefined ? writable : false; | ||
//enumerate = enumerate !== undefined ? enumerate : enumerable; | ||
//Object.defineProperty(obj, name, | ||
//{ | ||
//enumerable: enumerate, | ||
//configurable: false, | ||
//writable: writable, | ||
//value: value | ||
//} | ||
//); | ||
//} | ||
function define(obj, name, value, writable) { | ||
writable = writable || false; | ||
Object.defineProperty(obj, name, | ||
{ | ||
enumerable: enumerable, | ||
configurable: false, | ||
writable: writable, | ||
value: value | ||
} | ||
); | ||
} | ||
/** | ||
@@ -583,5 +481,7 @@ * Abstract super class. | ||
var finder = {}; | ||
for(var k in helpers) { | ||
finder[k] = helpers[k].bind(this); | ||
} | ||
define(this, 'finder', finder, false); | ||
@@ -877,3 +777,3 @@ | ||
var pkg; | ||
if(path && typeof(path) === 'string' && fs.existsSync(path)) { | ||
if(path && typeof(path) === 'string') { | ||
try { | ||
@@ -883,3 +783,3 @@ pkg = this._package = require(path); | ||
throw new Error(util.format( | ||
'package parse error %s (malformed json)', path)); | ||
'package error %s (%s)', path, e.message.toLowerCase())); | ||
} | ||
@@ -930,4 +830,2 @@ }else if(path && typeof path === 'object') { | ||
module.exports.sortNames = sortNames; | ||
module.exports.toDescription = toDescription; | ||
module.exports.Description = Description; | ||
module.exports.getNoVariants = getNoVariants; |
{ | ||
"name": "cli-define", | ||
"version": "0.6.7", | ||
"version": "0.6.8", | ||
"description": "Chainable argument builder for a command line interface", | ||
@@ -25,3 +25,4 @@ "author": "muji <noop@xpm.io>", | ||
"dependencies": { | ||
"cli-util": "^1.1.19", | ||
"cli-description": "^1.0.3", | ||
"cli-util": "^1.1.26", | ||
"markzero": "^0.1.27" | ||
@@ -28,0 +29,0 @@ }, |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11
22.22%1
-66.67%34128
-2.55%3
50%876
-3.95%+ Added
+ Added
Updated