{"name":"argue-cli","version":"2.0.0","keywords":["cli","arguments","parser","console","terminal"],"author":{"name":"dangreen"},"license":"MIT","_id":"argue-cli@2.0.0","maintainers":[{"name":"dangreen","email":"danon0404@gmail.com"}],"homepage":"https://github.com/TrigenSoftware/Argue#readme","bugs":{"url":"https://github.com/TrigenSoftware/Argue/issues"},"dist":{"shasum":"2efb3379f62b4256f3c9a7f3b458ae3add8abafc","tarball":"http://registry-npm.ywwl.com/argue-cli/download/argue-cli-2.0.0.tgz","fileCount":21,"integrity":"sha512-t0Nn8sxf7dPtQRDZyyzrjnfPYw7/yYC46mVqGgy4oCa0wwWgB7wooqVLTUPZ1z5Kk1FUc8LZFTXhegU1oy1xXw==","signatures":[{"sig":"MEUCIBQSowEb7EABFOgeCBMRHHbJcv8m5Nz6z5JfT8W9JoT0AiEAnuJt27y6Ort/TtiypqXtQUDIyUh7kqr4heFm1289XqU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":47273,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh5xzsCRA9TVsSAnZWagAADX0P/2TbbpXslzqs3D4yPNeS\n7xCcXAiWwLI2/MxP6pPxl1rICMq5v1jPI3oST8QlMf3+tyRc4SOzozFdi1uQ\nHXdVqM9zLOYswyZ49Yzo11Veup8oQHWdbAbqXCo7YngaRvcwZ2oB1ZCLVXjm\nwQTqzyOFub+3jDs0cV59nbQjLExvbW0vplKUM5oXHSbWrK2Mj0u7YvU+rZYa\n15pDWDNjZO9NTpTSlCNqa9sSns0YLpKPWyxtlZkvxrDe1xmbs+tVu8GDXJ+Z\n6ZUMTKnaTIToSInNNkeXhF51sBLTclnxNLwH0O6GcrexUAtI/w5P70ZU+gn+\nTNUUld5qzjhuUyWP3WQYlOdlM/0BlIGxwBi7Qjug928k+r1E3SSU3fwoizwn\nYHuloXDIUCppjcwPeJv2ysUbuW+areikrhCT/AfM+zK0zKp2iF4kWIx3tByB\nK3JCC6RiECxJXWF+iu39dlRtpITMIHFzhweQ3LMfdvn2/QxuzV2jyfX7yZHp\nrYqnW7gdPmSnOP+rBze3yWDa9FWjXMDlN7CGaS3MTi9Xtc0Kd6xbzTtCazhV\n+r/BwMuPjJOfsGT4zQnsvDYIkWp0wGXV6c9pKUP2jroYfS+G87VJQaaWLOYE\n0yC40F7/qljsFUUu92z7YIVCGUUMiQFPMRwIUN8HU+SULyrf2lviafxAw72O\nriBn\r\n=k1a2\r\n-----END PGP SIGNATURE-----\r\n","size":8786,"noattachment":false,"key":"/argue-cli/-/argue-cli-2.0.0.tgz"},"main":"./dist/index.cjs","type":"module","_from":"file:argue-cli-2.0.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=14.0.0"},"exports":{"import":{"default":"./dist/index.js"},"require":{"default":"./dist/index.cjs"}},"scripts":{},"_npmUser":{"name":"dangreen","email":"danon0404@gmail.com"},"_resolved":"","_integrity":"","repository":{"url":"git+https://github.com/TrigenSoftware/Argue.git","type":"git"},"_npmVersion":"6.14.15","description":"A thin and strongly typed CLI argument parser for Node.js.","directories":{},"_nodeVersion":"14.18.3","publishConfig":{"main":"./dist/index.cjs","module":"./dist/index.js","exports":{"import":{"default":"./dist/index.js"},"require":{"default":"./dist/index.cjs"}},"directory":"package"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/argue-cli_2.0.0_1642536172479_0.19630554484715024","host":"s3://npm-registry-packages"},"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":1642536172862,"_cnpm_publish_time":1642536172862,"dist-tags":{"latest":"3.2.1"}}