argp: Command-line Option Parser

1.0.4 · maintenance · verified Tue Apr 21

argp is a command-line option parser inspired by the GNU argp C library. It focuses on robust parsing of GNU-style options, automatic generation of comprehensive help, usage, and version messages with proper line-wrapping at 80 columns. A key design principle is its 'zero memory footprint' after parsing, achieved by uncaching the module and deleting properties once all input parameters are processed. The package, currently at stable version 1.0.4, offers basic error checking, support for command configuration, and an evented system for customization. It differentiates itself through its strict adherence to GNU-style parsing conventions and its minimal post-execution resource usage, making it suitable for CLI tools prioritizing resource efficiency and standard compliance.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic parsing of GNU-style options and arguments, automatic help message generation, and version display.

const argp = require('argp');

// If not using multiple parser instances or reusing a parser, 'once: true'
// guarantees a zero memory footprint by uncaching the module.
const argv = argp.createParser({ once: true })
    .description('Sample app.')
    .email('a@b.c')
    .body()
        // Defines arguments and options while simultaneously configuring help text.
        .text(' Arguments:')
        .argument('arg', { description: 'Sample argument' })
        .text('\n Options:')
        .option({ short: 'o', long: 'opt', description: 'Sample option' })
        .help()
        .version('v1.2.3')
    .argv();

console.log(argv);

// To test, run:
// node your-script.js --opt value --arg argument_value
// node your-script.js --help
// node your-script.js --version

view raw JSON →