New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

Handle --help and --version arguments in your CLI application

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-72.55%
Maintainers
1
Weekly downloads
 
Created
Source

npm

help-version

Build Status Dependency Status

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 given code;
  • highly configurable: you can set process.argv, stdout and stderr streams, and even process.exit function — this means testing won't be a problem.

Example

#!/usr/bin/env node

var Cli = require('help-version');

var cli = Cli('Usage:  my-cat [file]');

cli.version()
//=> "v0.1.0"

if (process.argv.length != 3) {
  // Show help and exit with code 1.
  cli.help(1);
}

fs.createReadStream(process.argv[2])
  .pipe(process.stdout);

Catches --help and --version automatically.

$ ./cat.js --help
Usage:  my-cat [file]
$ ./cat.js --version
v0.1.0
$ ./cat.js file.txt
contents of file.txt

API

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.

  1. If --help is found, prints helpText to opts.stdout and calls opts.exit.

  2. If --version is found, prints app version (determined from the version field from your local package.json) to opts.stdout and calls opts.exit.

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

OptionDefault
argvprocess.argv.slice(2)
exit([code])process.exit
stdoutprocess.stdout
stderrprocess.stderr

cli.help([code], [stream])

With no arguments, returns the help string.

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.

cli.version([code], [stream])

With no arguments, returns the version 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.

Install

npm install help-version

License

MIT

Keywords

FAQs

Package last updated on 16 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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