string-argv
string-argv parses a string into an argument array to mimic process.argv. This is useful when testing Command Line Utilities that you want to pass arguments to.
Last updated a year ago by cellule .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install string-argv 
SYNC missed versions from official npm registry.

What is it?

string-argv parses a string into an argument array to mimic process.argv. This is useful when testing Command Line Utilities that you want to pass arguments to and is the opposite of what the other argv utilities do.

Installation

npm install string-argv --save

Usage

// Typescript
import stringArgv from 'string-argv';

const args = stringArgv(
  '-testing test -valid=true --quotes "test quotes" "nested \'quotes\'" --key="some value" --title="Peter\'s Friends"',
  'node',
  'testing.js'
);

console.log(args);
// Javascript
var { parseArgsStringToArgv } = require('string-argv');

var args = parseArgsStringToArgv(
    '-testing test -valid=true --quotes "test quotes" "nested \'quotes\'" --key="some value" --title="Peter\'s Friends"',
    'node',
    'testing.js'
);

console.log(args);
/** output
[ 'node',
  'testing.js',
  '-testing',
  'test',
  '-valid=true',
  '--quotes',
  'test quotes',
  'nested \'quotes\'',
  '--key="some value"',
  '--title="Peter\'s Friends"' ]
  **/

params

required: arguments String: arguments that you would normally pass to the command line.

optional: environment String: Adds to the environment position in the argv array. If ommitted then there is no need to call argv.split(2) to remove the environment/file values. However if your cli.parse method expects a valid argv value then you should include this value.

optional: file String: file that called the arguments. If omitted then there is no need to call argv.split(2) to remove the environment/file values. However if your cli.parse method expects a valid argv value then you should include this value.

Current Tags

  • 0.3.1                                ...           latest (a year ago)

9 Versions

  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (2)
Downloads
Today 522
This Week 43,068
This Month 213,282
Last Day 10,682
Last Week 57,477
Last Month 183,860
Dependencies (0)
None
Dev Dependencies (2)
Dependents (133)

Copyright 2014 - 2016 © taobao.org |