{"id":13526804,"url":"https://github.com/nodeca/argparse","last_synced_at":"2025-05-14T12:07:58.449Z","repository":{"id":3285147,"uuid":"4325614","full_name":"nodeca/argparse","owner":"nodeca","description":"CLI arguments parser for node.js. JS port of python's argparse module.","archived":false,"fork":false,"pushed_at":"2023-11-09T18:31:05.000Z","size":381,"stargazers_count":499,"open_issues_count":7,"forks_count":74,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-06T19:28:20.752Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodeca.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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},"funding":{"open_collective":"puzrin","patreon":"puzrin","tidelift":"npm/argparse"}},"created_at":"2012-05-14T15:30:37.000Z","updated_at":"2025-04-30T23:44:35.000Z","dependencies_parsed_at":"2023-11-13T05:35:04.597Z","dependency_job_id":"88ee8378-b094-46de-bab4-fb930fb970cf","html_url":"https://github.com/nodeca/argparse","commit_stats":{"total_commits":221,"total_committers":25,"mean_commits":8.84,"dds":0.5882352941176471,"last_synced_commit":"a645a9a9d3d0a347f383d0b795859e67dfae6ad8"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fargparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fargparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fargparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fargparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeca","download_url":"https://codeload.github.com/nodeca/argparse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253521983,"owners_count":21921624,"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":[],"created_at":"2024-08-01T06:01:35.231Z","updated_at":"2025-05-14T12:07:58.387Z","avatar_url":"https://github.com/nodeca.png","language":"JavaScript","readme":"argparse\n========\n\n[![CI](https://github.com/nodeca/argparse/workflows/CI/badge.svg?branch=master)](https://github.com/nodeca/argparse/actions)\n[![NPM version](https://img.shields.io/npm/v/argparse.svg)](https://www.npmjs.org/package/argparse)\n\nCLI arguments parser for node.js, with [sub-commands](https://docs.python.org/3.9/library/argparse.html#sub-commands) support. Port of python's [argparse](http://docs.python.org/dev/library/argparse.html) (version [3.9.0](https://github.com/python/cpython/blob/v3.9.0rc1/Lib/argparse.py)).\n\n**Difference with original.**\n\n- JS has no keyword arguments support.\n  -  Pass options instead: `new ArgumentParser({ description: 'example', add_help: true })`.\n- JS has no python's types `int`, `float`, ...\n  - Use string-typed names: `.add_argument('-b', { type: 'int', help: 'help' })`.\n- `%r` format specifier uses `require('util').inspect()`.\n\nMore details in [doc](./doc).\n\n\nExample\n-------\n\nFollowing code is a JS program that takes a list of integers and produces either the sum or the max:\n\n```js\nconst { ArgumentParser } = require('argparse')\n\nconst parser = new ArgumentParser({ description: 'Process some integers.' })\n\nlet sum = ints =\u003e ints.reduce((a, b) =\u003e a + b)\nlet max = ints =\u003e ints.reduce((a, b) =\u003e a \u003e b ? a : b)\n\nparser.add_argument('integers', { metavar: 'N', type: 'int', nargs: '+',\n                                  help: 'an integer for the accumulator' })\nparser.add_argument('--sum',    { dest: 'accumulate', action: 'store_const',\n                                  const: sum, default: max,\n                                  help: 'sum the integers (default: find the max)' });\n\nlet args = parser.parse_args()\nconsole.log(args.accumulate(args.integers))\n```\n\nAssuming the JS code above is saved into a file called prog.js, it can be run at the command line and provides useful help messages:\n\n```\n$ node prog.js -h\nusage: prog.js [-h] [--sum] N [N ...]\n\nProcess some integers.\n\npositional arguments:\n  N           an integer for the accumulator\n\noptional arguments:\n  -h, --help  show this help message and exit\n  --sum       sum the integers (default: find the max)\n```\n\nWhen run with the appropriate arguments, it prints either the sum or the max of the command-line integers:\n\n```\n$ node prog.js 1 2 3 4\n4\n$ node prog.js 1 2 3 4 --sum\n10\n```\n\nIf invalid arguments are passed in, it will issue an error:\n\n```\n$ node prog.js a b c\nusage: prog.js [-h] [--sum] N [N ...]\nprog.js: error: argument N: invalid 'int' value: 'a'\n```\n\nThis is an example ported from Python. You can find detailed explanation [here](https://docs.python.org/3.9/library/argparse.html).\n\n\nAPI docs\n--------\n\nSince this is a port with minimal divergence, there's no separate documentation.\nUse original one instead, with notes about difference.\n\n1. [Original doc](https://docs.python.org/3.9/library/argparse.html).\n2. [Original tutorial](https://docs.python.org/3.9/howto/argparse.html).\n3. [Difference with python](./doc).\n\n\nargparse for enterprise\n-----------------------\n\nAvailable as part of the Tidelift Subscription\n\nThe maintainers of argparse and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-argparse?utm_source=npm-argparse\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo)\n","funding_links":["https://opencollective.com/puzrin","https://patreon.com/puzrin","https://tidelift.com/funding/github/npm/argparse","https://tidelift.com/subscription/pkg/npm-argparse?utm_source=npm-argparse\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo"],"categories":["Repository","JavaScript"],"sub_categories":["Command-line Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fargparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodeca%2Fargparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fargparse/lists"}