2.3.1 • Published 6 years ago

@clitools/base v2.3.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

@clitools/base

Base module for writing advanced shell scripts with Node.js.

At it's core it uses Yargs for option and parameter parsing, so it's a good idea to look at that documentation first.

Features

The target is to have a base module for writing Linux shell scripts, with APIs for most common CLI tasks, like:

Install

$ npm i --save @clitools/base
[...]

Example

example-tool:

#!/usr/bin/env node

require('./lib/cli');


cli.program
    .command('test <param>', 'Example command', (program) => {
        program
            .positional('param', {
                description: 'Test parameter'
            });
    }, ({ param }) => {
        cli.ui.startProgress('Test...');
        return cli.promises.throttle([
            () => Promise.resolve(param),
            () => Promise.resolve('A'),
            () => Promise.resolve('B'),
            () => Promise.resolve('C'),
            () => Promise.resolve('D'),
            () => Promise.resolve('E'),
            () => Promise.resolve('F'),
            () => Promise.resolve('G'),
            () => Promise.resolve('H'),
            () => Promise.resolve('I'),
            () => Promise.resolve('X')
        ], 1000, (p) => {
            cli.ui.updateProgress(p);
        })
            .then((result) => {
                cli.ui.stopProgress();
                cli.ui.print(result);
            });
    });

cli.run();

Output:

$ ./example-tool
Usage:
example-tool <command>

Commands:
  example-tool test <param>  Example command
  example-tool completion    generate bash completion script

Options:
  -v, --verbose  Show more information                      [count]
  -s, --silent   No output                                  [boolean]
  -d, --debug    Debug mode (stacktraces, very verbose)     [boolean]
  -h, --help     Show help                                  [boolean]
  -V, --version  Show version number                        [boolean]


Error:
Not enough non-option arguments: got 0, need at least 1

Changelog