JSPM

  • Created
  • Published
  • Downloads 27294
  • Score
    100M100P100Q125105F
  • License MIT

Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a few plugins, like 'base-store', 'base-options' and 'base-data'.

Package Exports

  • base-cli

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (base-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

base-cli NPM version

Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a few plugins, like 'base-store', 'base-options' and 'base-data'.

Adds a cli method to base for mapping parsed command line arguments existing base methods or custom functions.

The goal is to simplify the process of settings up command line logic for your base-methods application.

Install

Install with npm

$ npm i base-cli --save

Usage

var cli = require('base-cli');
var base = require('base-methods');
var app = base();

// register the `cli` plugin with [base-methods][]:
app.use(cli());

API

This adds a cli object to base with the following (chainable) methods (base.cli.*):

  • .map() - .map: add mappings from command line flags/options to custom functions or base methods
  • .alias() - .alias: similar to map but creates simple aliases. For example, alias('show', 'get') would invoke the .get() method when --show is passed on the command line
  • .process() - .process: once all mappings are defined, pass argv to .process() to iterate over the mappings, passing argv as context.

Example

var expand = require('expand-args');
var argv = require('minimist')(process.argv.slice(2));
var base = require('base-methods');
var cli = require('base-cli');

var app = base();
app.use(cli());

app.cli
  .map('foo', function(key, val) {
    app.get(key, val);
  })
  .map('bar', function(key, val) {
    app.set(key, val);
  })

app.cli.process(expand(argv));

// command line args:
//   
//   '--set=a:b --get=a'
//   
// prints:
//   
//   'a'
//   

base-methods plugins

Other useful plugins for base-methods:

  • base-config: base-methods plugin that adds a config method for mapping declarative configuration values to other 'base'… more | homepage
  • base-data: adds a data method to base-methods. | homepage
  • base-methods: Starter for creating a node.js application with a handful of common methods, like set, get,… more | homepage
  • base-options: Adds a few options methods to base-methods, like option, enable and disable. See the readme… more | homepage
  • base-plugins: Upgrade's plugin support in base-methods to allow plugins to be called any time after init. | homepage
  • base-store: Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object… more | homepage

Tests

Running tests

Install dev dependencies:

$ npm i -d && npm test

Coverage

Statements : 100% (13/13)
Branches   : 100% (2/2)
Functions  : 100% (4/4)
Lines      : 100% (12/12)

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on October 28, 2015.