{"name":"argue-cli","version":"2.0.0-1","keywords":["cli","arguments","parser","console","terminal"],"author":"dangreen","license":"MIT","_id":"argue-cli@2.0.0-1","maintainers":[{"name":"dangreen","email":"danon0404@gmail.com"}],"bugs":{"url":"https://github.com/TrigenSoftware/Argue/issues"},"dist":{"shasum":"34e951f04bd3aba4f5902e1bb7274778deb19389","tarball":"http://registry-npm.ywwl.com/argue-cli/download/argue-cli-2.0.0-1.tgz","fileCount":21,"integrity":"sha512-XFTjqUFWL4syY3J5sjM3JW7TOo4eB2wGCoWEM/NcVozH1h77GKNjKHhql0utV2fkDoxZkM4HnaAQHq/t3u/v7A==","signatures":[{"sig":"MEUCIAKI5m9ZAnCd4isb7+/qQoUYSmwPMrKDVuIr1fO5cqScAiEAnuf9OdlG5FBAyRnzycrFOdz0juzw3Zr8hXawIUyff6c=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":46246,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh5WaVCRA9TVsSAnZWagAAoyIP/2lr8R2y1+mrpvq+wrGK\nqZ9hJlwC5hm1tiGgpdngaS1jAAsFE6hLa0Ck1vtCRcC3nv9zQ7HJ/D8MVWXB\naei0w2Ch6EMY/q5C+36zac1Bur77J65vW8asHWQF+4sIgx721q4ayQWHlB5D\nf0zLoJvkuuarQX0ZvWVXroKA2q+thi5kHmksvthWNz1wWQFHXmqTSp0WHZZf\nYOFriR40WxLVAjUepXvh4NeL1WAThmTG4GhcS0/Rp4Aw7otYJSlrdSucg8Tl\nQjjz1eBGQWK4PngUK9vj6sdnEGk1MuFFIXO0ny/+shMDVO7S5at+B2C5MBSF\nM6nbu2GiyUrOFo90oXXYj8a1Lf0a9NMD6LRMStkZghp2iTr5mG2qWSvlOfxd\nk6ber91scpbtHlN8tGP3FJSCD+SBCSgU6WQYGtMPLtD2+n63nGPz9ICow0TX\nAc7W4KukNGlTlY79bhirTohXC8evQTEyAuPjNWj4aVax1r0AlQcN94zq6lNH\ntnzOpyiS2/cDGJsZLlz/Lc3SxoGz3Yo6+edrA83SUI2+sjrMsCi79jbPBzYt\nQzSisBVtEppOK2iXUrEwuJt6fv81ZGNC8LKFTumSKT3j2oItnH1AhSVNMI4r\nYGFL3Ym3Z6ytlpJpQNIMUDI/SgRKC2Y7s1T7vgOJlTfM94XbOTDpHHRttfuo\nVQ6J\r\n=QQng\r\n-----END PGP SIGNATURE-----\r\n","size":8680,"noattachment":false,"key":"/argue-cli/-/argue-cli-2.0.0-1.tgz"},"main":"./dist/index.cjs","type":"module","_from":"file:argue-cli-2.0.0-1.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":"/Users/dangreen/github/Argue/package/argue-cli-2.0.0-1.tgz","_integrity":"sha512-XFTjqUFWL4syY3J5sjM3JW7TOo4eB2wGCoWEM/NcVozH1h77GKNjKHhql0utV2fkDoxZkM4HnaAQHq/t3u/v7A==","repository":{"url":"https://github.com/TrigenSoftware/Argue.git","type":"git"},"_npmVersion":"7.24.0","description":"A thin and strongly typed CLI argument parser for Node.js.","directories":{},"_nodeVersion":"16.10.0","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-1_1642423957771_0.05422359765682194","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":1642423957900,"_cnpm_publish_time":1642423957900,"dist-tags":{"latest":"3.2.1"}}