991c154f922c656eb65846382b70dbf06c5337b9f0f4c5b1d43894e50fb08ba62a981470a9956d47a6987f66b4fccb7b40f88e67ae310db768876371370689 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # What is it?
  2. `string-argv` parses a string into an argument array to mimic `process.argv`.
  3. 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.
  4. # Installation
  5. ```
  6. npm install string-argv --save
  7. ```
  8. # Usage
  9. ```ts
  10. // Typescript
  11. import stringArgv from 'string-argv';
  12. const args = stringArgv(
  13. '-testing test -valid=true --quotes "test quotes" "nested \'quotes\'" --key="some value" --title="Peter\'s Friends"',
  14. 'node',
  15. 'testing.js'
  16. );
  17. console.log(args);
  18. ```
  19. ```js
  20. // Javascript
  21. var { parseArgsStringToArgv } = require('string-argv');
  22. var args = parseArgsStringToArgv(
  23. '-testing test -valid=true --quotes "test quotes" "nested \'quotes\'" --key="some value" --title="Peter\'s Friends"',
  24. 'node',
  25. 'testing.js'
  26. );
  27. console.log(args);
  28. /** output
  29. [ 'node',
  30. 'testing.js',
  31. '-testing',
  32. 'test',
  33. '-valid=true',
  34. '--quotes',
  35. 'test quotes',
  36. 'nested \'quotes\'',
  37. '--key="some value"',
  38. '--title="Peter\'s Friends"' ]
  39. **/
  40. ```
  41. ## params
  42. __required__: __arguments__ String: arguments that you would normally pass to the command line.
  43. __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.
  44. __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.