arg-parser (v2.0.1) is a lightweight, declarative command-line interface (CLI) argument parser specifically designed for Node.js applications. It enables developers to define and parse application-specific command-line arguments, including switches, required positional arguments, and descriptive help messages. The library allows for clear separation of argument definition from parsing logic, providing a structured approach to CLI development. While functional, the package has not seen active development or releases in several years, despite specifying Node.js >=18.0.0 in its `engines` field. This contrasts with more actively maintained alternatives like `yargs` or `commander.js`, which offer more advanced features, active community support, and frequent updates for modern Node.js environments. Its key differentiator is simplicity and a minimal API for basic argument parsing requirements.
npm install arg-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining various types of command-line arguments (required, optional, switches, values) and parsing them using the `Args` class.
Thoroughly test `arg-parser` with your specific Node.js version and project dependencies. Consider migrating to a more actively maintained CLI parser for long-term projects.
Always explicitly set `value: 'file'` or `value: 'text'` (or similar descriptive string) in the `add` configuration object for arguments that are intended to receive a string value.
Always refer to the constructor signature: `new Args(cliName: string, cliVersion: string, cliDescription: string, cliEpilog: string);` to ensure the correct information is displayed in the generated `--help` message.
Implement custom pre-parsing validation if you need more granular control over error messages or wish to prevent `process.exit()` in certain scenarios. Otherwise, rely on the library's built-in error reporting.
Change `const Args = require('arg-parser');` to `import Args from 'arg-parser';` Ensure your `package.json` has `"type": "module"` or your file uses the `.mjs` extension for ESM support in Node.js.Ensure all arguments marked as `required: true` are present in the command-line invocation, e.g., `node your-script.js --required-arg-name value`.
Define all expected command-line switches using `args.add({ name: '...', switches: ['--unknown-switch'] })` or correct the typo in the command line if it was intended to be a known switch.No dependency data recorded yet.