Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-bin-help

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-bin-help - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

97

index.js

@@ -1,31 +0,55 @@

function noArguments(minLength, args) {
console.assert(Array.isArray(args), 'missing arguments');
return args.length < minLength;
'use strict'
const updateNotifier = require('update-notifier')
function isHelp (arg) {
return arg === '-h' ||
arg === '--help'
}
function showHelp(options) {
var helpMessage = options.help || options.helpMessage;
function hasHelpArgument (args) {
return args.some(isHelp)
}
var pkg;
if (options.package) {
pkg = options.package;
} else if (options.packagePath) {
pkg = require(options.packagePath);
function noArguments (minLength, args) {
console.assert(Array.isArray(args), 'missing arguments')
return args.length < minLength
}
function getPackage (options) {
var pkg = options.pkg || options.package
if (!pkg && options.packagePath) {
pkg = require(options.packagePath)
}
var pkgInfo;
return pkg
}
function showHelp (options) {
var helpMessage = options.help || options.helpMessage
var pkg = getPackage(options)
var pkgInfo
if (pkg) {
pkgInfo = pkg.name + '@' + pkg.version + '\n - ' + pkg.description;
pkgInfo = pkg.name ? pkg.name : ''
if (pkg.version) {
pkgInfo += '@' + pkg.version
}
if (pkg.description) {
pkgInfo += '\n - ' + pkg.description
}
}
if (pkgInfo) {
console.log(pkgInfo);
console.log(pkgInfo)
}
if (helpMessage) {
console.log(helpMessage);
console.log(helpMessage)
}
if (!pkgInfo && !helpMessage) {
console.log('Incorrect CLI arguments');
console.log('Incorrect CLI arguments')
if (pkg && pkg.name) {
console.log('Check out instructions for this module using `npm home ' + pkg.name + '`');
console.log('Check out instructions for this module using `npm home ' + pkg.name + '`')
}

@@ -35,23 +59,44 @@ }

function simpleBinHelp(options, cliArguments) {
console.assert(options, 'missing options');
function finish (options) {
if (options.noExit) {
return false
}
process.exit(0)
}
function simpleBinHelp (options, cliArguments) {
console.assert(options, 'missing options')
if (!cliArguments) {
cliArguments = process.argv;
cliArguments = process.argv
}
if (hasHelpArgument(cliArguments)) {
showHelp(options)
finish(options)
return true
}
var pkg = getPackage(options)
if (pkg && pkg.name && pkg.version) {
updateNotifier({ pkg: pkg }).notify()
}
var minArguments = options.minArguments ||
options.min ||
options.n;
options.n
if (noArguments(minArguments, cliArguments)) {
showHelp(options);
if (options.noExit) {
return false;
showHelp(options)
if (typeof options.onFail === 'function') {
options.onFail()
}
process.exit(0);
return finish(options)
}
return true;
return true
}
module.exports = simpleBinHelp;
module.exports = simpleBinHelp

@@ -5,9 +5,11 @@ {

"main": "index.js",
"version": "1.2.0",
"version": "1.3.0",
"scripts": {
"test": "mocha spec",
"test": "mocha --harmony spec",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"commit": "git-issues && commit-wizard",
"issues": "git-issues",
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";"
"size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";",
"lint": "standard *.js spec/*.js examples/*.js",
"basic": "node --harmony examples/basic.js"
},

@@ -43,3 +45,4 @@ "files": [

"pre-git": "1.4.0",
"semantic-release": "4.3.5"
"semantic-release": "4.3.5",
"standard": "5.4.1"
},

@@ -50,3 +53,5 @@ "config": {

"pre-commit": [
"npm test"
"npm run lint",
"npm test",
"npm run basic"
],

@@ -59,3 +64,6 @@ "pre-push": [

}
},
"dependencies": {
"update-notifier": "0.5.0"
}
}

@@ -11,2 +11,3 @@ # simple-bin-help

[![semantic-release][semantic-image] ][semantic-url]
[![standard](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

@@ -41,4 +42,5 @@ ## Install

minArguments: n, // min number of arguments to check
pkg: packageObject, // package object or path for better message
packagePath: 'path/to/package.json'
pkg: packageObject, // package (or pkg) object or path for better message
packagePath: 'path/to/package.json',
onFail: fn // user-supplied function to be called after help has been shown
};

@@ -51,2 +53,10 @@ require('simple-bin-help')(options);

For more examples, see [examples/basic.js](examples/basic.js) file that calls the method
with several permutations.
## Bonus features
* Includes and calls the [update-notifier]() module by default.
* If passed `-h` or `--help` option, shows the help message.
### Small print

@@ -53,0 +63,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc