npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

yargs-get-help

1.1.1 • Public • Published

yargs-get-help

NPM version Downloads Build Status Coverage Status Dependency status Dev Dependency status Greenkeeper badge

Get the help output from a yargs instance.

This module is very handy when you are developing tests for a project that has a CLI, specially when used in conjunction with snapshot testing.

Installation

$ npm install yargs-get-help

Usage

getHelp(yargs, [options])

import yargs from 'yargs';
import getHelp from 'yargs-get-help';
 
yargs
.option('include', { type: 'boolean', describe: 'This is the include option' });
 
const help = getHelp(yargs);
// `help` will contain yargs `$0 --help` output as a string

getHelp(yargs, [args], [options])

import yargs from 'yargs';
import getHelp from 'yargs-get-help';
 
yargs
.command('serve', 'Start the server', (yargs) => {
    yargs
    .option('port', {
        describe: 'The port to bind on',
        default: 5000,
    });
}, (argv) => {
    serve(argv.port);
})
.command('build', 'Builds the project', (yargs) => {
    yargs
    .option('public-path', {
        describe: 'The webpack public-path',
        default: '/',
    });
}, (argv) => {
    build(argv.publicPath);
});
 
const help = getHelp(yargs, ['serve']);
// `help` will contain yargs `$0 serve --help` output as a string

Available options:

  • normalize: Normalizes the output, unifying things like terminal sizes, locale, $0 and ansi-codes (defaults to true)

NOTE: This package mutates the passed yargs instance. If this is a problem, please consider using yargs/yargs instead.

Tests

$ npm test
$ npm test -- --watch during development

License

MIT License

install

npm i yargs-get-help

Downloadsweekly downloads

29

version

1.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability