arg is a minimalist, unopinionated command-line argument parser for Node.js applications. It focuses on providing a straightforward API for defining and parsing CLI options, including type conversion (String, Number, Boolean, custom functions), flag counting (e.g., `--verbose -vvv`), and aliasing. The current stable version is 5.0.2, with recent patch releases addressing type fixes and dependency updates, while major releases are infrequent but cautious, aiming for minimal disruption. It prioritizes simplicity and direct mapping of arguments to values, leaving validation and requirement checking to the application layer. This makes it suitable for projects needing a lightweight parsing solution without bundled opinionated features common in larger CLI frameworks.
npm install argVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic setup with type definitions, option parsing (including counts and arrays), aliases, and basic error handling.
Update error handling logic to check `e.code` for specific error types (e.g., 'ARG_UNKNOWN_OPTION') or `e instanceof ArgError` for general `arg`-related errors.
Ensure all keys in your argument specification object (the first argument to `arg()`) are properly prefixed with one or two hyphens.
Use `String`, `Number`, or a custom type function for options that require a value. Only use `Boolean`, `[Boolean]`, or `arg.flag()` for options that are presence-based switches.
Access `parsedArgs._` to retrieve any non-option arguments. Remember that `_` is always an array, even if empty.
Change the import statement to `import arg from 'arg';` and run your script as an ES module.
Define `--some-undefined-option` in the `arg` specification object, or set `permissive: true` in the options object if you want to allow unknown options (they will be added to `_`).
Ensure that options expecting values are followed by a value (e.g., `--port 8080` or `--port=8080`). If the option should be a flag without a value, change its type to `Boolean` or use `arg.COUNT` or `arg.flag()`.
No dependency data recorded yet.