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-2/

CLI Flag Parser

Build a command-line argument parser that handles boolean flags and basic string options for a deployment tool.

Requirements

Create a parser that processes command-line arguments with the following behavior:

Flag Handling

  • Support long flags that start with -- (e.g., --verbose, --force)
  • Support short flags that start with - (e.g., -v, -f)
  • Flags should be boolean - their presence sets them to true
  • Flags should not consume the next argument value

String Options

  • Support string options using --name value syntax
  • Support string options using --name=value syntax

Short Flag Aliasing

  • Allow short flags to act as aliases for long flags (e.g., -v for --verbose)
  • Both forms should produce the same result in the parsed output

Positional Arguments

  • Collect arguments that don't match any defined options
  • Store them in a _ property as an array

Test Cases

  • --verbose should parse as { verbose: true, _: [] } @test
  • -v aliased to --verbose should parse as { verbose: true, _: [] } @test
  • --force --verbose should parse as { force: true, verbose: true, _: [] } @test
  • --name Alice should parse as { name: 'Alice', _: [] } @test
  • --verbose deploy production should parse as { verbose: true, _: ['deploy', 'production'] } @test

Implementation

@generates

API

/**
 * Parses command-line arguments according to a specification.
 *
 * @param {Object} spec - Specification object mapping argument names to types or aliases
 * @param {Array<string>} [argv] - Optional array of arguments to parse (defaults to process.argv.slice(2))
 * @returns {Object} Parsed arguments with a `_` property for positional args
 */
function parseArgs(spec, argv) {
  // IMPLEMENTATION HERE
}

module.exports = { parseArgs };

Dependencies { .dependencies }

arg { .dependency }

Provides CLI argument parsing support.

Install with Tessl CLI

npx tessl i tessl/npm-arg

tile.json