1.0.0 • Published 8 years ago

mtd-help v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

mtd-help

NPM version Downloads

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.

// simple.js
'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 {
    /*
     * The name of your application,
     * displayed at the top of the help print out.
     */
    name: string;

    /*
     * Whether to list the track that is
     * associated with the block generated
     * in the final output.
     */
    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

1.0.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago