Comparing version 1.0.0 to 1.0.1
25
index.js
@@ -0,1 +1,3 @@ | ||
var parseArgs = require('minimist'); | ||
var isSelf = function(parent){ | ||
@@ -12,10 +14,19 @@ if (!(this instanceof isSelf)) { | ||
isSelf.prototype.run = function(){ | ||
var method = process.argv[2]; | ||
var parentMethods = this.parent.exports; // module which called isSelf | ||
var args = parseArgs(process.argv); | ||
var method = args.m; | ||
var parent = this.parent.exports; // module which called isSelf | ||
if (method){ | ||
if (!parent[ method ]){ | ||
var msg = 'Module does not have a "'+method+ '" method'; | ||
throw new Error(msg); | ||
} | ||
parent[ method ].apply( parent, args._.slice(2) ); | ||
} else { | ||
if (typeof parent !='function'){ | ||
var msg = 'Module is not a function'; | ||
throw new Error(msg); | ||
} | ||
parent.apply( parent, args._.slice(2) ); | ||
} | ||
if (!parentMethods[ method ]){ | ||
var msg = 'Module does not have a "'+method+ '" method'; | ||
throw new Error(msg); | ||
} | ||
parentMethods[ method ].apply( parentMethods, process.argv.slice(3) ); | ||
}; | ||
@@ -22,0 +33,0 @@ isSelf.prototype.checkAndRun = function(){ |
{ | ||
"name": "is-self", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Check if module is self-evoked. Run module methods directly from command line", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test/asFunction arg1 arg2; node test/asObject.js -m run arg1 arg2 " | ||
}, | ||
"author": "Anton Miselaytes <anton@wearereasonablepeople.com>", | ||
"license": "ISC" | ||
"license": "ISC", | ||
"dependencies": { | ||
"minimist": "^1.2.0" | ||
} | ||
} |
@@ -28,4 +28,4 @@ # Overview | ||
node veryUsefulModule methodA 1 2 // foo=1, bar=2, bax=undefined | ||
node veryUsefulModule -m methodA 1 2 // foo=1, bar=2, bax=undefined | ||
node veryUsefulModule methodC 1 2 // Module does not have a "methodC" method | ||
node veryUsefulModule -m methodC 1 2 // Module does not have a "methodC" method |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
44
1
2425
1
6
+ Addedminimist@^1.2.0
+ Addedminimist@1.2.8(transitive)