{"library":"options-parser","title":"Command Line Options Parser","description":"options-parser is a lightweight, full-featured command-line argument parser for Node.js, designed with no external dependencies for a minimal footprint. The current stable version is 0.4.0, indicating it's still in active development, likely with a focus on stability before a 1.0 release. Its key differentiators include built-in type validation for common types (like files), automatic help screen generation with customizable formatting, and robust handling of multi-value options and default values. It provides a structured way to define expected command-line flags and arguments, distinguishing between required, optional, and flag-only parameters, making it suitable for scripting and CLI tool development in Node.js environments.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install options-parser"],"cli":null},"imports":["const options = require('options-parser');","const result = options.parse(optsConfig, argv);","const typeValidation = options.type.file.open.write();","options.help(optsConfig, helpOptions);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const options = require('options-parser');\n\n// Define your command-line options structure\nconst optsConfig = {\n  user:  { required: true, help: 'Specify the user name for authentication.' },\n  all:   { short: 'a', flag: true, help: 'Process all available items (boolean flag).' },\n  host:  { short: 'h', default: 'localhost', help: 'Target host address for connection.' },\n  input: { short: 'i', multi: true, help: 'Input file paths (can be specified multiple times).' },\n  r:     { flag: true, help: 'Enable recursive mode for file operations.' },\n  db:    { default: 'test', help: 'Database name to connect to, defaults to \\'test\\'.' },\n  out:   { short: 'o', type: options.type.file.open.write(), help: 'Output file path with write access.' }\n};\n\n// Simulate command line arguments for demonstration purposes.\n// In a real application, this would typically be `process.argv.slice(2)`.\nconst simulatedArgv = [\n  '--user=joe',\n  '-a',\n  '--host',\n  'www.example.com',\n  'output.txt',\n  '-i',\n  'file1.txt',\n  '--input',\n  'file2.txt',\n  '-o',\n  'out.txt'\n];\n\n// Parse the arguments based on the defined configuration\nconst result = options.parse(optsConfig, simulatedArgv);\n\nconsole.log('--- Parsed Options and Arguments ---');\nconsole.log(JSON.stringify(result, null, 2));\n\n// Generate and log the help screen based on the same configuration\nconsole.log('\\n--- Generated Help Screen ---');\noptions.help(optsConfig, { output: console.log, columns: 80, paddingLeft: 2 });\n","lang":"javascript","description":"This quickstart demonstrates how to define a comprehensive set of command-line options including required fields, flags, default values, multi-value options, and type validation. It then parses a simulated argument array, logs the resulting structured data, and showcases the package's ability to automatically generate a formatted help screen.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}