Extract command-line arguments from a list, removing matches from the original array
Latest commit 2b1003b Feb 23, 2014 @hughsk 0.0.1
Failed to load latest commit information.
LICENSE.md first commit Feb 15, 2014
README.md typo: of -> off Feb 15, 2014
index.js first commit Feb 15, 2014
package.json 0.0.1 Feb 23, 2014
test.js first commit Feb 15, 2014


extract-flags Flattr this!experimental

Extract command-line arguments from a list, removing matches from the original array. Useful for providing custom arguments for a wrapper executable, but passing unexpected arguments back onto the original executable if not expected.

Only supports a subset of what you'd get with minimist, so unless you're explicitly looking to modify the arguments array you're better off using that module.



extract(argv, flags)

Where argv is an array of arguments, and flags is an object formatted like so:

    t: String
  , transform: String
  , debug: Boolean

Each key represents a command-line flag, and the value should be either String, Number or Boolean to denote its type. argv will be modified in-place to remove matched flags, and you will get an object in return with the extracted values:

    t: ['envify', 'es6ify']
  , transform: ['installify']
  , debug: true


Here's a simple example of the kind of thing you might want to use extract-flags for:

var spawn = require('child_process').spawn
var extract = require('extract-flags')
var argv = process.argv

var options = extract(argv, {
    'transform': String
  , 'debug': Boolean

if (options.debug) {
  process.env.NODE_ENV = 'development'

var ps = spawn('node', argv.slice(1), {
    cwd: process.cwd()
  , env: process.env

var input = process.stdin
options.transform.forEach(function(tr) {
  input = input.pipe(require(tr)('filename'))


MIT. See LICENSE.md for details.