parse-cmd-args
TypeScript icon, indicating that this package has built-in type declarations

5.0.1 • Public • Published

parse-cmd-args

Returns an object containing the path and flags parsed from process.argv

Test Publish Documentation NPM version

Install

$ npm install parse-cmd-args --save

Usage

import { readFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import parseCmdArgs from 'parse-cmd-args';

const args = parseCmdArgs(null, {
  requireUserInput: true
});

if (args.flags['--version'] || args.flags['-v']) {
  process.stdout.write(
    `${
      JSON.parse(
        async readFile(
          join(dirname(fileURLToPath(import.meta.url)), '../package.json'),
          'utf8'
        )
      ).version
    }\n`
  );
  process.exit();
} else if (args.flags['--help'] || args.flags['-h']) {
  process.stdout.write(`Usage: example <path> ... [options]

  Options:

   -h, --help         Display this help message.
   -v, --version      Display the current installed version.
`);
  process.exit();
}

console.log(args);

/parse-cmd-args/

    Package Sidebar

    Install

    npm i parse-cmd-args

    Weekly Downloads

    420

    Version

    5.0.1

    License

    MIT

    Unpacked Size

    10.8 kB

    Total Files

    8

    Last publish

    Collaborators

    • neogeek