simple-hard-coded.js 540 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. // This example is used in the documentation.
  3. // 1. const { parseArgs } = require('node:util'); // from node
  4. // 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
  5. const { parseArgs } = require('..'); // in repo
  6. const args = ['-f', '--bar', 'b'];
  7. const options = {
  8. foo: {
  9. type: 'boolean',
  10. short: 'f'
  11. },
  12. bar: {
  13. type: 'string'
  14. }
  15. };
  16. const {
  17. values,
  18. positionals
  19. } = parseArgs({ args, options });
  20. console.log(values, positionals);
  21. // Try the following:
  22. // node simple-hard-coded.js