Registry / http-networking / oppa
library0.5.0jsnpmunverified

Oppa is a typesafe options and arguments parser for Node.js, designed for command-line interfaces. It provides a fluent API for defining command-line arguments, including support for long/short names, aliases, boolean flags (with `--no-` prefix auto-handling), multi-value arguments, and custom validators. A key differentiator is its strong TypeScript integration, which ensures the parsed result is fully type-checked at compile-time, eliminating common runtime errors associated with parsing untyped arguments. It also automatically generates comprehensive `--help` and `--version` output. The current stable version is 0.4.0, released in June 2021, indicating a slower release cadence. It requires Node.js >=10, with specific build fixes for Node.js 10 in versions 0.3.3 and later.

npm install oppa
INSTALL
IMPORT
SIG · OPPA
O
oppa
http-networkingjavascriptv0.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

oppa
import { oppa } from 'oppa'
const { oppa } = require('oppa')
Primary export for creating a new parser instance. While CommonJS `require` might work with older Node.js versions, ESM `import` is the recommended pattern, especially for TypeScript projects.
Oppa
import { Oppa } from 'oppa'
Type export for the Oppa instance itself, useful for type hinting or extending the parser configuration.
TypeOf
import { TypeOf } from 'oppa'
Type helper to infer the exact TypeScript type of the parsed options object from an oppa instance, leveraging the parser's configuration.

Demonstrates defining various argument types (string, number, boolean), setting defaults, applying validators, and handling parsed results with TypeScript safety. It also shows how to configure `noExit` and `throwOnError` for programmatic control.

import { oppa } from 'oppa'; const cliArgs = process.argv.slice(2); // Get actual CLI arguments const parser = oppa({ name: 'myapp', version: '1.2.3', usage: 'myapp [options] <files...>', description: 'A utility for file operations.', noExit: true, // Prevent process exit for better testing/embedding throwOnError: true // Throw errors instead of printing help and exiting }) .add({ name: 'file', alias: 'f', type: 'string', description: 'The primary file to process.', defaultValue: 'default.txt' }) .add({ name: 'retry', alias: 'r', type: 'number', description: 'Number of retries before failing.', defaultValue: 3, validator: (v: number) => v >= 0 }) .add({ name: 'force', type: 'boolean', defaultValue: false, description: 'Force operation, overwriting existing files.' }) .add({ name: 'verbose', alias: 'v', type: 'boolean', description: 'Enable verbose logging.', noHelpAlias: true // Allows -v to be used here, if --version is also noVersionAlias }); try { const result = parser.parse(cliArgs); if (result.args.force) { console.log('Force mode enabled.'); } console.log(`Processing file: ${result.args.file}`); console.log(`Retries configured: ${result.args.retry}`); if (result.rest.length > 0) { console.log(`Additional files: ${result.rest.join(', ')}`); } // Example of accessing type-safe properties // result.args.retry.toFixed(0); // This is type-safe due to 'type: number' } catch (error) { if (error instanceof Error) { console.error(`CLI Error: ${error.message}`); } else { console.error('An unknown CLI error occurred.'); } parser.showHelp(); // Show help on error if throwOnError is true process.exit(1); }
Debug
Known issues
gotchaThe `oppa` package has not been updated since June 2021 (v0.4.0). While functional, it might not receive active maintenance for new Node.js features, security patches, or bug fixes promptly.
fix
Evaluate if the current feature set meets your application's needs. If active development, latest Node.js compatibility, or rapid bug fixes are critical, consider alternative argument parsers.
affects: >=0.4.0
gotchaBy default, `oppa` will call `process.exit()` after printing help or version information, or on encountering an error (unless `throwOnError` is true). This can interrupt program flow in test environments or when embedding the parser in a larger application.
fix
Initialize `oppa` with `{ noExit: true }` to prevent automatic process termination. You will then need to handle program termination or continuation explicitly in your application logic.
affects: *
gotchaOppa requires Node.js version 10 or higher. Using it with older versions (e.g., Node.js 8) may lead to unexpected errors or runtime failures due to ES2018 build targets.
fix
Ensure your Node.js environment is version 10 or greater. Version 0.3.3 specifically addressed a build issue for Node.js 10, making it the minimum recommended version for stable Node.js 10 support.
affects: <0.3.3
gotchaThe default behavior for unknown arguments (i.e., arguments not explicitly defined using `.add()`) is to throw an error. This can lead to abrupt program termination if users provide unexpected flags.
fix
Initialize `oppa` with `{ allowUnknown: true }` to collect unknown arguments in the `result.unknown` array instead of throwing an error. This allows your application to gracefully handle or ignore unrecognized input.
affects: *
gotchaThe auto-generated `--help` and `--version` arguments implicitly create short aliases `-h` and `-v`. If you intend to use these short aliases for other custom arguments (e.g., `-v` for `verbose`), it will cause conflicts.
fix
Initialize `oppa` with `{ noHelpAlias: true }` and/or `{ noVersionAlias: true }` to prevent the automatic creation of `-h` and `-v` aliases, freeing them up for your custom argument definitions.
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
Attempting to call a method or access a property on a parsed option that is `undefined` because it was not provided in the arguments, or trying to use a method that doesn't exist on its inferred type (e.g., `toLowerCase()` on a boolean).
fix
Ensure that optional arguments are checked for `undefined` before use, or provide `defaultValue` in your `.add()` definition. If it's a type mismatch, explicitly set the `type` property (e.g., `type: 'string'`) in your argument definition, and TypeScript will catch such errors at compile-time.
Oppa: unknown argument: --foo
The parser encountered a command-line argument (`--foo`) that was not explicitly defined using `.add()`, and the `allowUnknown` option is not enabled.
fix
Either define the argument using `.add()` in your parser configuration, or initialize `oppa` with `{ allowUnknown: true }` to collect unknown arguments in the `result.unknown` array instead of throwing an error.
Error: process.exit() was called
This error typically occurs in test runners when `oppa`'s default behavior of calling `process.exit()` is triggered (e.g., by `--help`, `--version`, or an error without `throwOnError`).
fix
Initialize `oppa` with `{ noExit: true }` to prevent automatic process termination. This allows test runners to complete without interruption and gives your application explicit control over exiting.
Oppa: Argument validation failed for 'retries'
A custom `validator` function defined for an argument returned `false` (or threw an error), indicating the provided value is invalid.
fix
Review the `validator` function for the specific argument and ensure it correctly handles expected input ranges or formats. Inform the user about the valid input for that argument in the help text.
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
oppa — npm install oppa · libregistry