mtd-help
![Downloads](http://img.shields.io/npm/dm/mtd-help.svg)
This module provides an easy way to define a help
track for applications using mtd.
Install
Using npm.
$ npm install mtd-help
Example
A simple example.
'use strict';
const Depot = require('mtd');
const help = require('mtd-help');
new Depot()
.default('help', [], help(
{ name: 'Help Example',
hide: false },
{ foo: 'A line about foo.',
bar: 'A line about bar.',
help: 'Display this message.' }
))
.track(
'foo',
[
{ $: 'zal', alias: 'z', info: 'A description for zal.' },
{ $: 'qux', _: 'hello, world', alias: 'q', info: 'A description for qux.' }
],
(zal, qux) => console.log(zal, qux)
)
.track(
'bar',
[ { $: 'baz', alias: 'b', info: 'A description for baz.' } ],
baz => console.log(baz)
)
.embark();
Running our example application either as $ node simple.js
or verbosely as $ node simple.js help
will print the following to our terminal, complete with pretty colours.
Help Example
[ Multiple: On ][ Reruns: Off ][ Warnings: On ]
[ bar ] A line about bar.
--baz, -b
A description for baz.
[ foo ] A line about foo.
--zal, -z
A description for zal.
--qux, -q (default: hello, world)
A description for qux.
[ help ] (default) Display this message.
Documentation
Require the module, as you would any other Node module.
const help = require('mtd-help');
help
is now a factory function that creates a suitable Track
block. It has the following signature.
factory (
settings: HelpSettings,
descriptions: GenericObject = {}
): Block
HelpSettings
is an interface that looks like:
interface HelpSettings {
name: string;
hide: boolean;
}
descriptions
is a GenericObject
:
interface GenericObject extends Object {
[index: string]: any;
}
Its keys should be strings, corresponding to Track
handles in your application. Each value should be a description of the matching track.
Enjoy!
oka.io