@clitools/base
Base module for writing advanced shell scripts with Node.js
Last updated 2 years ago by hhornbacher .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @clitools/base 
SYNC missed versions from official npm registry.

@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

Current Tags

  • 2.3.1                                ...           latest (2 years ago)

9 Versions

  • 2.3.1                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.2.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0-pre1                                ...           2 years ago
  • 1.6.1                                ...           2 years ago
  • 1.6.0                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 11
This Month 11
Last Day 0
Last Week 0
Last Month 12
Dependencies (9)
Dev Dependencies (6)

Copyright 2014 - 2016 © taobao.org |