← Runnable Projects

阅读中文版本

Node Minimal Argparse CLI

Node Minimal Argparse — a runnable typescript project with source, install and run commands, and expected output.

intermediatetypescriptunverified

Project

node-argparse-minimal-cli

Entry point: argparse.mjs

Install

node argparse.mjs --name Alice --count 3

Run

node argparse.mjs --name Alice --count 3

Test

node --test argparse.test.mjs

Expected output

Parses --key value flags from argv into an object and prints it as JSON.

Dependencies

  • node >=20

Verification evidence

Source reviewed against typescript standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Node Minimal Argparse CLI is a self-contained typescript command-line program. Parses –key value flags from argv into an object and prints it as JSON.

Install and run

node argparse.mjs --name Alice --count 3
node argparse.mjs --name Alice --count 3

Project structure

node-argparse-minimal-cli/
├── argparse.mjs
└── README snippet above

Key source

// argparse.mjs
const out={};const a=process.argv.slice(2);
for(let i=0;i<a.length;i+=2)out[a[i].replace(/^--/,"")]=a[i+1];
console.log(JSON.stringify(out));

Testing

node --test argparse.test.mjs

Expected output

When run with the documented command, the program prints:

{ "name": "Alice", "count": "3" }

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.