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

help-version

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

help-version - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

16

index.js

@@ -6,3 +6,4 @@ 'use strict';

var callsites = require('callsites');
var callsites = require('callsites'),
once = require('once');

@@ -21,2 +22,5 @@

return function (code, stream) {
if (typeof data == 'function') {
data = data();
}
if (code == null) {

@@ -34,5 +38,9 @@ return data;

module.exports = function (help, opts) {
module.exports = function (helpText, opts) {
opts = opts || {};
var getHelp = typeof helpText == 'function'
? once(helpText)
: function () { return helpText };
// Copy to a separate object to accomodate for passing `process` object with

@@ -52,3 +60,3 @@ // getters.

case '--help':
write.call(options, help);
write.call(options, getHelp());
options.exit();

@@ -64,5 +72,5 @@ break;

return {
help: maybeExit.call(options, help),
help: maybeExit.call(options, getHelp),
version: maybeExit.call(options, version)
};
};
{
"name": "help-version",
"version": "1.0.0",
"description": "Easily handle --help and --version arguments in your CLI application",
"version": "1.1.0",
"description": "Handle --help and --version arguments in your CLI application",
"author": "Eugene Sharygin <eush77@gmail.com>",

@@ -24,14 +24,22 @@ "license": "MIT",

"cli",
"bin",
"argv",
"opts",
"help",
"version",
"argument",
"arguments",
"usage",
"option",
"options",
"flag",
"flags",
"application",
"program"
"program",
"testable"
],
"dependencies": {
"callsites": "^1.0.0",
"find-root": "^0.1.1"
"find-root": "^0.1.1",
"once": "^1.3.3"
},

@@ -38,0 +46,0 @@ "devDependencies": {

@@ -7,4 +7,10 @@ [![npm](https://nodei.co/npm/help-version.png)](https://nodei.co/npm/help-version/)

Automatic handling of `--help` and `--version` arguments for CLI applications.
Anything you wanted to do with `--help` and `--version`:
- checks these arguments in `process.argv`, so you don't have to;
- extracts `version` from your `package.json` file;
- returns functions that give you both `--help` and `--version`, in case you need to handle them differently;
- returns the function that prints `--help` and exits with the given1 code;
- highly configurable: you can set `process.argv`, `stdout` and `stderr` streams, and even `process.exit` function — you can use it for testing.
[travis]: https://travis-ci.org/eush77/help-version

@@ -20,18 +26,15 @@ [travis-badge]: https://travis-ci.org/eush77/help-version.svg

var helpVersion = require('help-version')(usage());
var Cli = require('help-version');
function usage() {
// Makes use of function declarations hoisting.
return 'Usage: my-cat [file]';
}
helpVersion.version()
var cli = Cli('Usage: my-cat [file]');
cli.version()
//=> "v0.1.0"
if (process.argv.length != 3) {
// Shows help and exits with code 1.
helpVersion.help(1);
// Show help and exit with code 1.
cli.help(1);
}
// Main thing.
fs.createReadStream(process.argv[2])

@@ -54,4 +57,6 @@ .pipe(process.stdout);

### `helpVersion = require('help-version')(helpText, [opts])`
### `cli = Cli(helpText, [opts])`
- `helpText` {String | Function} — help text to print on `--help`, or function to produce it.
Checks `opts.argv` for `--help` or `--version`.

@@ -63,3 +68,3 @@

Returns object with two (bound) methods: `helpVersion.help([code], [stream])` and `helpVersion.version([code], [stream])`.
Returns object with two (bound) methods: `cli.help([code], [stream])` and `cli.version([code], [stream])`.

@@ -73,9 +78,9 @@ | Option | Default |

### `helpVersion.help([code], [stream])`
### `cli.help([code], [stream])`
With no arguments, returns the help string.
With one or two arguments, writes it to the `stream` instead and exits (via `opts.exit`) with `code`. `stream` defaults to `opts.stdout` if `code==0` and `opts.stderr` otherwise.
With one or two arguments, writes it to `stream` instead and exits (via `opts.exit`) with `code`. `stream` defaults to `opts.stdout` if `code==0` and `opts.stderr` otherwise.
### `helpVersion.version([code], [stream])`
### `cli.version([code], [stream])`

@@ -82,0 +87,0 @@ With no arguments, returns the version string.

Sorry, the diff of this file is not supported yet

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