Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including impulse-bin with all npm packages installed. Try it out:

var impulseBin = require("impulse-bin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

impulse-bin v0.2.0

CLI module runner

impulse-bin

node.js CLI module runner

Build Status

Purpose

  • CLI scripts that are easier to test without running the executable.
  • Reduce boilerplate.

Example

bin/myproj

Executables are reduced to thin loading calls.

var bin = require('impulse-bin').create();
bin.run(require('commander'), require('./lib/cli/myproj'));

// Or if your CLI module's run() function is a generator:
bin.runGenerator(require('commander'), require('./lib/cli/myproj'));

lib/cli/myproj.js

While the rest is separated into input parsing and input consumption.

  • init() receives a CLI input provider like commander.js or node-optimist for you to configure.
  • run() receives the parsed this.options and this.args from the provider.
exports.init = function(provider) {
  provider.option('-c, --config <dir>', 'Config file');
};

exports.run = function() {
  this.exitOnMissingOption(['config']);

  this.stdout('using config file: %s', this.clc.green(this.options.config));

  // ...
};

Pass arguments from bin/myproj to the lib/cli/myproj.js

// bin/myproj
bin.run(require('commander'), require('./lib/cli/myproj'), 1, 2, 3);

// lib/cli/myproj.js
exports.run = function() {
  console.log([].slice.call(arguments)); // [1, 2, 3]
};

Installation

NPM

NPM

npm install impulse-bin

Documentation

License

MIT

Tests

npm test

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free