{"id":15497520,"url":"https://github.com/bcomnes/argsclopts","last_synced_at":"2025-04-22T22:03:48.483Z","repository":{"id":214244979,"uuid":"736062444","full_name":"bcomnes/argsclopts","owner":"bcomnes","description":"cliclopts but for Node.js parseArgs","archived":false,"fork":false,"pushed_at":"2025-03-06T18:12:20.000Z","size":52,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T16:16:29.337Z","etag":null,"topics":["cli","helptext","nodejs","parseargs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/argsclopts","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bcomnes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["bcomnes"],"custom":["https://bret.io"]}},"created_at":"2023-12-26T22:05:21.000Z","updated_at":"2025-03-06T18:12:23.000Z","dependencies_parsed_at":"2024-11-08T19:02:00.452Z","dependency_job_id":"7f040cc4-cab6-4c6c-a1e8-b46e78df00f7","html_url":"https://github.com/bcomnes/argsclopts","commit_stats":null,"previous_names":["bcomnes/argsclopts"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fargsclopts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fargsclopts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fargsclopts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bcomnes%2Fargsclopts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bcomnes","download_url":"https://codeload.github.com/bcomnes/argsclopts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250331804,"owners_count":21413100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","helptext","nodejs","parseargs"],"created_at":"2024-10-02T08:39:15.740Z","updated_at":"2025-04-22T22:03:48.412Z","avatar_url":"https://github.com/bcomnes.png","language":"JavaScript","readme":"# argsclopts\n[![latest version](https://img.shields.io/npm/v/argsclopts.svg)](https://www.npmjs.com/package/argsclopts)\n[![Actions Status](https://github.com/bcomnes/argsclopts/workflows/tests/badge.svg)](https://github.com/bcomnes/argsclopts/actions)\n[![Coverage Status](https://coveralls.io/repos/github/bcomnes/argsclopts/badge.svg?branch=master)](https://coveralls.io/github/bcomnes/argsclopts?branch=master)\n[![downloads](https://img.shields.io/npm/dm/argsclopts.svg)](https://npmtrends.com/argsclopts)\n[![Types in JS](https://img.shields.io/badge/types_in_js-yes-brightgreen)](https://github.com/voxpelli/types-in-js)\n[![Socket Badge](https://socket.dev/api/badge/npm/package/argsclopts)](https://socket.dev/npm/package/argsclopts)\n\n[cliclopts](https://github.com/finnp/cliclopts) but for [Node.js parseArgs](https://nodejs.org/api/util.html#utilparseargsconfig). A library that formats standard usage strings using the `node:util` `parseArgs` `options` object shape with an additional `help` field added to it.\n\n```\nnpm install argsclopts\n```\n\n## Usage\n\n``` js\nimport { printHelpText } from 'argsclopts'\nimport { join } from 'node:path'\nimport { parseArgs } from 'node:util'\n\n/**\n * @typedef {import('argsclopts').ArgscloptsParseArgsOptionsConfig} ArgscloptsParseArgsOptionsConfig\n */\n\nconst pkgPath = join(import.meta.dirname, 'package.json')\n\n/** @type {ArgscloptsParseArgsOptionsConfig} */\nconst options = {\n  foo: {\n    type: 'boolean',\n    short: 'f',\n    help: 'A foo flag thats a boolean'\n  },\n  bar: {\n    type: 'string',\n    help: 'A bar flag thats a string'\n  }\n}\n\nawait printHelpText({\n  options,\n  pkgPath\n})\n/*\n\nUsage: argsclopts [options]\n\n    Example: argsclopts\n\n    --foo, -f             A foo flag thats a boolean\n    --bar                 A bar flag thats a string\n\nargsclopts (v1.0.0)\n\n */\n\nconst args = ['-f', '--bar', 'b']\nconst { values } = parseArgs({ args, options })\nconsole.log(values)\n// { foo: true, bar: 'b' }\n```\n\n## API\n\n### `import { formatHelpText, printHelpText, usage, header, footer } from 'argsclopts'`\n\nYou can import `formatHelpText`, `printHelpText`, `usage`, `header`, `footer` from `argsclopts`.\ns\n### `helpText = formatHelpText({ options, [pkgPath], [name], [version], [footerFn], [headerFn], [exampleFn]})`\n\nGenerate the `helptText` string. Requires passing in an `options` object that you provide to [`parseArgs`](https://nodejs.org/api/util.html#utilparseargsconfig), with one additional field per flag: `help`. You should also provide `pkgPath` (a resolved path the `package.json`) so that a bin name and version can be resolved. Otherwise, pass in a `name` and `version` to override any resolved data from `pkgPath`. If both  `name` and `version` are provided, a `pkgPath` is required. The `headerFn`, and `exampleFn` can be used to override the header text and the `footerFn` can be used to override the footer text.\n\nAn example `options` object might look like this:\n\n```js\nconst options = {\n  foo: {\n    type: 'boolean',\n    short: 'f',\n    help: 'A foo flag thats a boolean'\n  },\n  bar: {\n    type: 'string',\n    help: 'A bar flag thats a string'\n  }\n}\n```\n\n\n### `void printHelpText({ options, [pkgPath], [name], [version], [footerFn], [headerFn], [exampleFn]})`\n\nExactly the same as `formatHelpText` except it uses `console.log` to print the text for you. Returns nothing.\n\n### `usageText = usage(options)`\n\nGenerate just the usage string with a given `options` object.\n\n### `headerText = header({ [pkgPath], [name], [headerFn], [exampleFn] })`\n\nGenerate the headerText only. Pass in either a `pkgPath` string path to the `package.json` of the bin you are printing for, or a `name`. The `headerFn` and `exampleFn` allow you to override the header text that is generated. Each function receilves an object with a `name` key.\n\n### `footerText = footer({ [pkgPath], [name], [version], [footerFn] })`\n\nGenerate the footerText only. Pass in either a `pkgPath` string path to the `package.json` of the bin you are printing for, or a `name` and/or `version`. The `footerFn` lets you override the footer text template and receives an object with a `name` and `version` key.\n\n## License\n\nMIT\n","funding_links":["https://github.com/sponsors/bcomnes","https://bret.io"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcomnes%2Fargsclopts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbcomnes%2Fargsclopts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbcomnes%2Fargsclopts/lists"}