Show-help

node module helpers to display help section given command line arguments

View project on GitHub

show-help

node module helpers to display help section given command line arguments

Install

npm i @maboiteaspam/show-help --save

Usage

function usage () {/*
...some text...
*/}
var pkg = require('./package.json')
require('@maboiteaspam/show-help')(usage, process.argv, pkg)

Usage

process.argv

Using the node process.argv value

function usage () {/*
module name
        ...

    Usage
        ...

    Options
        ...

    Examples
        ...
*/}
var pkg = require('./package.json')
require('@maboiteaspam/show-help')(usage, process.argv, pkg)
// require('@maboiteaspam/show-help')
//  .tpl('%name %version\n\t%description\n\n%usage')(usage, process.argv, pkg)

Which then, can be invoked in such fashion

module-name -h
module-name --help

minimist

Using minimist module to pre parse values

function usage () {/*
module name
        ...

    Usage
        ...

    Options
        ...

    Examples
        ...
*/}
var pkg  = require('./package.json')
var argv = require('minimist')(process.argv.slice(2));
require('@maboiteaspam/show-help')
    .tpl('%name %version\n\t%description\n\n%usage')(usage, argv.h||argv.help, pkg)
//require('@maboiteaspam/show-help')(usage, argv.h||argv.help, pkg)

Which then, can be invoked in such fashion

module-name -h
module-name --help

Api

showHelp

showHelp is a function to display help and exits when needed,

  • showHelp(callable fn, object arg, object pkg, int code) void

When typeof(arg) is object, detect (-h|--help), and figures out if usage should be displayed and program killed.

pkg is object of package.json file.

  • showHelp(callable fn, string arg, object pkg, int code) void

When typeof(arg) is string, and not falsy, it displays usage and kills the program with code.

pkg is object of package.json file.

  • showHelp(callable fn, bool arg, object pkg, int code) void

When typeof(arg) is bool, and not falsy, it displays usage and kills the program with code.

pkg is object of package.json file.

showHelp.tpl

showHelp.tpl is a function to set a template to render usage,

  • showHelp(string newTpl) showHelp

set tpl to newTpl, then returns showHelp for chaining.

showHelp.raw

showHelp.raw is a function to parse a string as a command line input. It detects -h|--help and invoke showHelp.parsed.

  • showHelp.raw(callable fn, object pkg, string arg) bool

When arg.match(/-h|--help/) is not falsy, it renders and displays usage.

showHelp.parsed

showHelp.parsed is a function to invoke showHelp.print when arg is not falsy.

  • showHelp.parsed(callable fn, object pkg, string arg) bool

When arg is not falsy, it renders and displays usage.

showHelp.print

showHelp.print is a function to render template given multilen(fn) usage string and pkg object, then print it on console.error.

  • showHelp.print(callable fn, object pkg) bool

Renders usage then print it on console.error.

More