{"name":"argue-cli","version":"2.0.0-2","keywords":["cli","arguments","parser","console","terminal"],"author":"dangreen","license":"MIT","_id":"argue-cli@2.0.0-2","maintainers":[{"name":"dangreen","email":"danon0404@gmail.com"}],"bugs":{"url":"https://github.com/TrigenSoftware/Argue/issues"},"dist":{"shasum":"32804b6611980a73a31d23ec49d7a225e312637d","tarball":"http://registry-npm.ywwl.com/argue-cli/download/argue-cli-2.0.0-2.tgz","fileCount":21,"integrity":"sha512-SLT/jd/70F3t2+1adbH+8p49K4ygIXKYqP9VZ71WAcOBm6c+7VEqM+IWORBS6Ze7Am1KwYMEPZa8iOP3PX40hQ==","signatures":[{"sig":"MEUCIDhIEFVgLot2LU/P2ybd/XNfLd1mALlPvc9qELZkncuFAiEA6deRuNw5jYMV8eEISj5uiQ8ZF0ocM1RrJ3wtLRiOQ6k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":47099,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh5Z6zCRA9TVsSAnZWagAABOQP/1UTqlgGOwPB5CYop0eL\nFQOLa4v6oSU0eooGtQDixcUYogUiOVLzT2LRwwH+52k0yX4gnJ+O9P18a83q\nPbY94+x4fBJjEeLQ3A7hIuIgU2SHjjN9TtpFTvGCjnX44OqaYsEHnP8ztDwY\nyAa1UtSKSXUJXB+UNXi1/K9jJUJKJi+VnB7rGnTiF0mYiBQkzPmpcAZlQgQp\nknZYnvpqz+31GTwIfkeu8g7V5PHsFZjg7nymAR9JbM3wLXkoREN90Vc0Pyga\nU42b5wZgtu+T0OlcHqV0u1tMyCNxOKeQqc3hypxSE+Bc8uU/mhfNg7v47XaQ\nw+9G6oELnj53dyjmxndqByEr6o/ozKS/6cfnBHYU6RL+roH+0S8KBOAAwUgc\n1/GCUPYjklPtWNVfgEXZysaZqQizOKmwr63QKocQni/a6q5EEURzWZ8p7Rhg\nlDC2bCTiJzcsoY53lRAAmFOBakZ5XsGU8izqcjS0VMZyUJu3FgTKhkJazzzC\nNOtHEGQtMI2hS4eSB7zq8i45Dk0b4t54GuLbqWX6azAmDKmjVAERtxrTneYx\nEGzREoLlCuvbrRqtUmtPOrwHpGAudiX1wn+8Qgg/Un0/VuoGw5t9IP9kaazP\nXhXOyJGLVFLrRxk0/GIt8oJldbnWoyJJlBAMyiM9dzi7OU6/qa+IKcGpX0iv\nxwbn\r\n=6/u8\r\n-----END PGP SIGNATURE-----\r\n","size":8748,"noattachment":false,"key":"/argue-cli/-/argue-cli-2.0.0-2.tgz"},"main":"./dist/index.cjs","type":"module","_from":"file:argue-cli-2.0.0-2.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-2.tgz","_integrity":"sha512-SLT/jd/70F3t2+1adbH+8p49K4ygIXKYqP9VZ71WAcOBm6c+7VEqM+IWORBS6Ze7Am1KwYMEPZa8iOP3PX40hQ==","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-2_1642438323370_0.21235897007291293","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":1642438323628,"_cnpm_publish_time":1642438323628,"dist-tags":{"latest":"3.2.1"}}