Detalhes do pacote

pargs

ljharb2.1kMIT1.1.0

A useful wrapper for util.parseArgs

parseArgs, parse, arguments, args

readme (leia-me)

pargs Version Badge

github actions coverage License Downloads

npm badge

A wrapper for node’s built-in util.parseArgs with helpful features added.

Usage

#!/usr/bin/env node

import pargs from 'pargs';

const {
    help,
    positionals,
    values,
    errors, // a mutable string array; push to it and pargs will include your error messages.
    name, // if subcommands are used
    tokens,
} = await pargs(import.meta.filename, options);

// do extra validation here

await help(); // to handle `--help` and print the help text if needed, or to print errors and exit

Help

Help text is automatically read from a help.txt file adjacent to import.meta.filename.

await an invocation of the help function returned from the pargs call to handle --help and print the help text if needed, or to print errors and exit.

Options

See the node.js parseArgs documentation for some context.

  • strict: can not be set to false - strictness all the way.
  • allowNegative: can not be set to false.
  • args: can not provide; pargs always uses process.cwd() - this may be added in the future, though.
  • options.type: in addition to 'boolean' and 'string', 'enum': when provided, a choices string array is also required.
  • allowPositionals: in addition to a boolean, or an integer representing the maximum number of allowed positional arguments.
  • minPositionals: an integer representing the minimum required number of positional arguments.
  • subcommands: if provided, must be an object. Keys are the subcommand names (eg, in npm ls, ls is the subcommand), and values are the configuration options for each subcommand - as if they were a top-level invocation.

Install

``

npm install --save pargs

License

MIT

Thanks

Thanks to @ibakaidov for donating the pargs package name!

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v2.0.0 - 2025-10-24

v1.1.0 - 2025-10-31

Commits

  • [New] add minPositionals option 3216189

v1.0.3 - 2025-10-30

Commits

  • [Fix] clean up help output 3418b5c

v1.0.2 - 2025-10-30

Commits

  • [Fix] when erroring, help output should always be sent to stdout, not stderr redux bc507ea

v1.0.1 - 2025-10-30

Commits

  • [Fix] when erroring, help output should always be sent to stdout, not stderr d948d1f

v1.0.0 - 2025-10-24

Commits

  • Complete package reimplementation. 659374e
  • [readme] add thanks 5c3c649

v0.3.0 - 2015-08-19

Commits

  • 0.3.0 Add examples, fix field bee007c

v0.2.3 - 2015-08-18

Commits

  • 0.2.3 Debug error in package.json 1d40ca6

v0.2.2 - 2015-08-18

Commits

  • 0.2.0 write docs, and add withoutError function de5374f
  • 0.2.1 Update README.md 9df97bf
  • 0.2.2 Bug npm 4a05c75

v0.1.1 - 2015-08-16

v0.1.0 - 2015-08-16