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

Command Executor with Argument Passthrough

Build a command-line tool that accepts its own configuration options while collecting additional unrecognized arguments to pass through to a subcommand.

Requirements

Your tool should parse command-line arguments with the following behavior:

  1. Recognize and parse a --verbose flag (boolean) for verbose output
  2. Recognize and parse a --config option (string) for configuration file path
  3. Collect all unrecognized arguments (both flags and positional arguments) into an array
  4. Support the -- terminator to treat all following arguments as positional
  5. Return a result object with parsed options and an array of collected arguments

Test Cases

  • When given --verbose --config=/path/to/config.json build deploy --force, should return verbose: true, config: "/path/to/config.json", and collected arguments ["build", "deploy", "--force"] @test

  • When given --verbose -- --config something, should return verbose: true, and collected arguments ["--config", "something"] (everything after -- is positional) @test

  • When given build test deploy, should return collected arguments ["build", "test", "deploy"] with no parsed options @test

  • When given --config=app.json command1 command2, should return config: "app.json" and collected arguments ["command1", "command2"] @test

Implementation

@generates

API

/**
 * Parses command-line arguments, extracting known options and collecting
 * positional arguments.
 *
 * @param {string[]} argv - The argument array to parse (e.g., process.argv.slice(2))
 * @returns {object} An object containing parsed options and a '_' property with positional arguments
 */
function parseArgs(argv) {
  // Implementation here
}

module.exports = { parseArgs };

Dependencies { .dependencies }

arg { .dependency }

CLI argument parser that supports option parsing and positional argument collection.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-arg

tile.json