=============== LIBRARY RULES =============== From library maintainers: - Use parseArgs(definition) with type coercion: type: 'number' | 'boolean' | 'string' - Short flags support inline values (-p8080) and grouped booleans (-abc) - Error aggregation — all missing required fields reported at once ### Parse CLI Arguments with Bun Args Source: https://github.com/nds-stack/bun-args/blob/main/README.md Demonstrates how to define and parse command-line arguments using `parseArgs`. Supports type coercion, aliases, default values, and required fields. Ensure all required arguments are provided. ```typescript import { parseArgs } from "@nds-stack/bun-args"; const args = parseArgs({ port: { alias: "p", type: "number", default: 3000 }, verbose: { alias: "v", type: "boolean", default: false }, config: { type: "string", required: true }, }); // bun run app.js --port 8080 -v --config prod console.log(args.port); // 8080 (number) console.log(args.verbose); // true (boolean) console.log(args.config); // "prod" console.log(args._); // ["input.txt"] ``` -------------------------------- ### parseArgs Function Source: https://github.com/nds-stack/bun-args/blob/main/README.md The `parseArgs` function is the primary interface for parsing CLI arguments. It takes a definition object specifying the expected arguments and an optional array of arguments to parse. ```APIDOC ## parseArgs(definition, argv?) ### Description Parses command-line arguments based on a provided definition object. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **definition** (object) - Required - An object defining the expected arguments, their types, aliases, defaults, and whether they are required. - **type** (string | number | boolean) - Auto-coerce value. - **alias** (string) - Short flag (e.g., "p" for -p). - **default** (unknown) - Fallback when not provided. - **required** (boolean) - Throw if missing. - **argv** (string[]) - Optional - An array of arguments to parse. If not provided, `process.argv` is used. ### Request Example ```typescript import { parseArgs } from "@nds-stack/bun-args"; const args = parseArgs({ port: { alias: "p", type: "number", default: 3000 }, verbose: { alias: "v", type: "boolean", default: false }, config: { type: "string", required: true }, }); // bun run app.js --port 8080 -v --config prod console.log(args.port); console.log(args.verbose); console.log(args.config); console.log(args._); ``` ### Response #### Success Response (200) - **args** (object) - An object containing the parsed arguments. Keys correspond to the definition keys. `args._` contains positional arguments. #### Response Example ```json { "port": 8080, "verbose": true, "config": "prod", "_": ["input.txt"] } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.