{"_id":"argue-cli@3.2.0","bugs":{"url":"https://github.com/TrigenSoftware/Argue/issues"},"dist":{"shasum":"15b9ff31e0ce316c9fd1ff1761188fa81995f1c5","tarball":"http://registry-npm.ywwl.com/argue-cli/download/argue-cli-3.2.0.tgz","fileCount":19,"integrity":"sha512-VipTB0gXgGIFO2Rg9yEVN5wLt2AurJcZqDbgmYSwPwsykhLrQhs240/bfceev4w68lI8JshoOJIk9uW7tFzROw==","signatures":[{"sig":"MEUCIQDe5WHFdXvTvs+R88SG71FJfYN2c14HnWl2DxUiUzfhPQIgNmCbrPkD4QlZMr13+YFeSlE0SJpST0fN+D1BCyAGGvQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCxdxNXzETpwq7XUCeXSS9TuGtuXoWSEQcMMoYudUEkZAIhAOot7ntLTEFv3z2gOnzi3dcKbbaF7XlpqMdoEqyExqSC"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/argue-cli@3.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":38799,"size":10687,"noattachment":false,"key":"/argue-cli/-/argue-cli-3.2.0.tgz"},"name":"argue-cli","type":"module","types":"./dist/index.d.ts","author":"dangreen","engines":{"node":">=22"},"exports":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"funding":"https://ko-fi.com/dangreen","license":"MIT","version":"3.2.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:e5a902b9-53bb-4a03-b41b-c6ed7e2293d0"}},"keywords":["cli","arguments","parser","console","terminal"],"repository":{"url":"https://github.com/TrigenSoftware/Argue.git","type":"git"},"description":"A thin and strongly typed CLI arguments parser for Node.js.","directories":{},"maintainers":[{"name":"dangreen","email":"danon0404@gmail.com"}],"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/argue-cli_3.2.0_1788267484023_0.4689979014566048"},"readme":"# argue-cli\n\n[![ESM-only package][package]][package-url]\n[![NPM version][npm]][npm-url]\n[![Node version][node]][node-url]\n[![Dependencies status][deps]][deps-url]\n[![Install size][size]][size-url]\n[![Build status][build]][build-url]\n[![Coverage status][coverage]][coverage-url]\n\n[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg\n[package-url]: https://nodejs.org/api/esm.html\n\n[npm]: https://img.shields.io/npm/v/argue-cli.svg\n[npm-url]: https://www.npmjs.com/package/argue-cli\n\n[node]: https://img.shields.io/node/v/argue-cli.svg\n[node-url]: https://nodejs.org\n\n[deps]: https://img.shields.io/librariesio/release/npm/argue-cli\n[deps-url]: https://libraries.io/npm/argue-cli\n\n[size]: https://packagephobia.com/badge?p=argue-cli\n[size-url]: https://packagephobia.com/result?p=argue-cli\n\n[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/Argue/tests.yml?branch=master\n[build-url]: https://github.com/TrigenSoftware/Argue/actions\n\n[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/Argue.svg\n[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/Argue\n\nA thin and strongly typed CLI arguments parser for Node.js.\n\n## Usage\n\n1. Install\n\n```bash\n# pnpm\npnpm add argue-cli\n# yarn\nyarn add argue-cli\n# npm\nnpm i argue-cli\n```\n\n2. Import in your code and use it!\n\n```ts\nimport { read, end, expect, alias, option, readOptions } from 'argue-cli'\n\n/**\n * Expect and read one of the commands\n */\nconst command = expect(\n  alias('install', 'i'),\n  'remove'\n)\nlet options = {}\n\nif (command === 'install') {\n  /**\n   * Read passed options\n   */\n  options = readOptions(\n    option(alias('save', 'S'), Boolean),\n    option(alias('saveDev', 'save-dev', 'D'), Boolean),\n    option('workspace', String)\n  )\n}\n\n/**\n * Read next argument\n */\nconst packageName = read()\n\n/**\n * Expect end of the arguments\n */\nend()\n\n/* ... */\n```\n\n## API\n\nArgue reads arguments sequentially from an internal state, which is initialized with `process.argv`. Every call consumes the arguments it reads, so you describe your CLI step by step: expect a command, read its options, read positional arguments, and finally assert the end.\n\n> [!TIP]\n> The internal state can be controlled manually with `setArgs(...args)` and `resetArgs()` — handy in tests.\n\n### read\n\n```ts\nfunction read(): string\n```\n\nReads the next argument and returns it. Throws an error if there are no arguments left.\n\n```ts\n// my-cli sort-imports\nconst fileName = read() // 'sort-imports'\n```\n\n### rest\n\n```ts\nfunction rest(): string[]\n```\n\nReads all remaining arguments and returns them. Returns an empty array if there are none — unlike [`read`](#read), it never throws.\n\n```ts\n// my-cli format a.js b.js c.js\nexpect('format')\n\nconst files = rest() // ['a.js', 'b.js', 'c.js']\n\nend() // always passes after rest()\n```\n\n### end\n\n```ts\nfunction end(): void\n```\n\nAsserts that all arguments were consumed. Throws an error if there are any arguments left — useful to catch typos and unexpected input.\n\n```ts\n// my-cli install --sav\nexpect('install')\nreadOptions(\n  option(alias('save', 'S'), Boolean)\n)\nend() // throws: Unexpected argument \"--sav\"\n```\n\n### expect\n\n```ts\nfunction expect(...argRefs: ArgRef[]): string\n```\n\nExpects the next argument to be one of the given ones and returns the matched name. If an [alias](#alias) matches, the main name is returned. Throws an error on any other input.\n\nThe return type is inferred as a union of the given names:\n\n```ts\n// my-cli i\nconst command = expect(alias('install', 'i'), 'remove')\n// typeof command: 'install' | 'remove'\n// command === 'install'\n```\n\n### alias\n\n```ts\nfunction alias(name: string, ...aliases: string[]): AliasArgRef\n```\n\nDescribes an argument that has alternative names. Use it anywhere an argument name is expected — in [`expect`](#expect) and [`option`](#option).\n\n```ts\nalias('install', 'i')\nalias('saveDev', 'save-dev', 'D')\n```\n\n### autocase\n\n```ts\nfunction autocase(argRef: ArgRef): ArgRef\n```\n\nDescribes an argument that matches both camelCase and kebab-case forms. The name can be given in either form — the twin form is added as an alias. Aliases longer than one character are autocased too. Use it anywhere an argument name is expected.\n\n```ts\nautocase('firstRelease')\n// --firstRelease and --first-release are both accepted\n\nautocase(alias('save-dev', 'D'))\n// --save-dev, --saveDev and -D\n```\n\n### option\n\n```ts\nfunction option(argRef: ArgRef, type: OptionConstructor): OptionReader\n```\n\nDescribes an option with a value of the given type, to be read by [`readOptions`](#readoptions):\n\n- `String` — takes the next argument as a value: `--workspace packages/app`\n- `Number` — parses the next argument as a number: `--port 8080`\n- `Boolean` — a flag without a value, `true` when present: `--verbose`\n- `Array` — splits the next argument by commas; repeated options are merged: `--plugins eslint,swc --plugins tsc` → `['eslint', 'swc', 'tsc']`\n- `[String]` or `[Number]` — takes the next argument as a whole; repeated options are collected: `--match '*.{js,ts}' --match '*.css'` → `['*.{js,ts}', '*.css']`. Use it instead of `Array` for values that may contain commas of their own\n\n### flag\n\n```ts\nfunction flag(argRef: ArgRef): OptionReader\n```\n\nDescribes a boolean flag with `--no-*` negation support, to be read by [`readOptions`](#readoptions): `--verbose` sets `true`, `--no-verbose` sets `false`. Use `option(argRef, Boolean)` when negation is not wanted.\n\n```ts\nconst options = readOptions(\n  flag(autocase('firstRelease'))\n)\n// --first-release → { firstRelease: true }\n// --no-first-release, --no-firstRelease → { firstRelease: false }\n```\n\n### readOptions\n\n```ts\nfunction readOptions(...optionReaders: OptionReader[]): OptionResult\n```\n\nScans the arguments and reads all described options. Both `--option` and `-o` prefixes are accepted, and a value can be passed either as the next argument or inline: `--workspace packages/app` and `--workspace=packages/app` are equivalent. Arguments that don't match any described option are left untouched, so you can continue reading them afterwards.\n\nThe result is a strongly typed object, where every property is optional — an option simply may not be passed:\n\n```ts\n// my-cli --save-dev --workspace packages/app my-package\nconst options = readOptions(\n  option(alias('saveDev', 'save-dev', 'D'), Boolean),\n  option('workspace', String)\n)\n// typeof options: { saveDev?: boolean, workspace?: string }\n// options: { saveDev: true, workspace: 'packages/app' }\n\nconst packageName = read() // 'my-package'\n```\n\n## TypeScript\n\nIn the [API section](#api) types are described in a simplified way. A detailed example of the inferred types you can see in [type tests](src/types.spec.ts).\n","publish_time":1788267484098,"_cnpm_publish_time":1788267484098,"dist-tags":{"latest":"3.2.1"}}