CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-arg

Unopinionated, no-frills CLI argument parser for Node.js applications

Overall
score

99%

Overview
Eval results
Files

task.mdevals/scenario-7/

Server Configuration Parser

A CLI argument parser for configuring a development server.

Capabilities

Parse server configuration options

The parser should handle command-line arguments to configure a development server with the following options:

  • --host: A string specifying the hostname (e.g., "localhost", "0.0.0.0")
  • --port: A numeric value specifying the port number (e.g., 3000, 8080)
  • --verbose: A boolean flag to enable verbose logging
  • --ssl: A boolean flag to enable SSL/TLS

The parser should support both space-separated syntax (--port 3000) and equals syntax (--port=3000) for all arguments.

Handle configuration file path

  • --config: A string specifying the path to a configuration file

Test cases

  • Parsing --host localhost --port 3000 returns an object with host "localhost" and port 3000 @test
  • Parsing --port=8080 --verbose returns an object with port 8080 and verbose true @test
  • Parsing --host=0.0.0.0 --port=443 --ssl returns an object with host "0.0.0.0", port 443, and ssl true @test
  • Parsing --config=/path/to/config.json --verbose returns an object with config path and verbose true @test

Implementation

@generates

API

/**
 * Parses command-line arguments for server configuration.
 *
 * @param {string[]} argv - Array of command-line arguments to parse
 * @returns {Object} Parsed configuration object with properties:
 *   - host: string (optional)
 *   - port: number (optional)
 *   - verbose: boolean (optional)
 *   - config: string (optional)
 *   - ssl: boolean (optional)
 *   - _: array of positional arguments
 */
function parseServerConfig(argv) {
  // IMPLEMENTATION HERE
}

module.exports = { parseServerConfig };

Dependencies { .dependencies }

arg { .dependency }

Provides CLI argument parsing support.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-arg

tile.json