{"library":"oppa","title":"Oppa Argument Parser","description":"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.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install oppa"],"cli":null},"imports":["import { oppa } from 'oppa'","import { Oppa } from 'oppa'","import { TypeOf } from 'oppa'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { oppa } from 'oppa';\n\nconst cliArgs = process.argv.slice(2); // Get actual CLI arguments\n\nconst parser = oppa({\n    name: 'myapp',\n    version: '1.2.3',\n    usage: 'myapp [options] <files...>',\n    description: 'A utility for file operations.',\n    noExit: true, // Prevent process exit for better testing/embedding\n    throwOnError: true // Throw errors instead of printing help and exiting\n})\n.add({\n    name: 'file',\n    alias: 'f',\n    type: 'string',\n    description: 'The primary file to process.',\n    defaultValue: 'default.txt'\n})\n.add({\n    name: 'retry',\n    alias: 'r',\n    type: 'number',\n    description: 'Number of retries before failing.',\n    defaultValue: 3,\n    validator: (v: number) => v >= 0\n})\n.add({\n    name: 'force',\n    type: 'boolean',\n    defaultValue: false,\n    description: 'Force operation, overwriting existing files.'\n})\n.add({\n    name: 'verbose',\n    alias: 'v',\n    type: 'boolean',\n    description: 'Enable verbose logging.',\n    noHelpAlias: true // Allows -v to be used here, if --version is also noVersionAlias\n});\n\ntry {\n    const result = parser.parse(cliArgs);\n\n    if (result.args.force) {\n        console.log('Force mode enabled.');\n    }\n    console.log(`Processing file: ${result.args.file}`);\n    console.log(`Retries configured: ${result.args.retry}`);\n    if (result.rest.length > 0) {\n        console.log(`Additional files: ${result.rest.join(', ')}`);\n    }\n    // Example of accessing type-safe properties\n    // result.args.retry.toFixed(0); // This is type-safe due to 'type: number'\n} catch (error) {\n    if (error instanceof Error) {\n        console.error(`CLI Error: ${error.message}`);\n    } else {\n        console.error('An unknown CLI error occurred.');\n    }\n    parser.showHelp(); // Show help on error if throwOnError is true\n    process.exit(1);\n}\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}