peach a19a732be8 commit message | 2 anni fa | |
---|---|---|
.. | ||
CHANGELOG.md | 2 anni fa | |
LICENSE | 2 anni fa | |
README.md | 2 anni fa | |
index.d.ts | 2 anni fa | |
index.js | 2 anni fa | |
package.json | 2 anni fa |
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.
npm install string-argv --save
// 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"' ]
**/
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.