{"id":21269586,"url":"https://github.com/fardjad/node-parse-my-command","last_synced_at":"2026-05-01T06:01:16.938Z","repository":{"id":192125418,"uuid":"686421310","full_name":"fardjad/node-parse-my-command","owner":"fardjad","description":"Parse argv with Commander.js without executing the command","archived":false,"fork":false,"pushed_at":"2026-04-17T03:34:52.000Z","size":282,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-17T05:31:04.362Z","etag":null,"topics":["argv","commander","commanderjs","nodejs","parser"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/parse-my-command","language":"TypeScript","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/fardjad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-09-02T18:27:45.000Z","updated_at":"2026-04-17T03:33:43.000Z","dependencies_parsed_at":"2024-04-13T22:33:31.623Z","dependency_job_id":"6201ca95-57d0-4b80-b949-86828b662c46","html_url":"https://github.com/fardjad/node-parse-my-command","commit_stats":{"total_commits":147,"total_committers":2,"mean_commits":73.5,"dds":"0.12244897959183676","last_synced_commit":"6ea8315747fd6cc00af8e843d099ed8ace7c062b"},"previous_names":["fardjad/node-parse-my-command"],"tags_count":145,"template":false,"template_full_name":null,"purl":"pkg:github/fardjad/node-parse-my-command","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-parse-my-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-parse-my-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-parse-my-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-parse-my-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fardjad","download_url":"https://codeload.github.com/fardjad/node-parse-my-command/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fardjad%2Fnode-parse-my-command/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32484414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["argv","commander","commanderjs","nodejs","parser"],"created_at":"2024-11-21T08:09:09.041Z","updated_at":"2026-05-01T06:01:16.919Z","avatar_url":"https://github.com/fardjad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parse My Command\n\nParse `argv` with **Commander.js** without executing the command\n\n\u003cdiv class=\"paragraph\"\u003e\n\n\u003cspan class=\"image\"\u003e\u003ca href=\"https://www.npmjs.com/package/parse-my-command\" class=\"image\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/parse-my-command\" alt=\"NPM Version\" /\u003e\u003c/a\u003e\u003c/span\u003e \u003cspan class=\"image\"\u003e\u003ca href=\"https://www.npmjs.com/package/parse-my-command\" class=\"image\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/parse-my-command\" alt=\"Monthly Downloads\" /\u003e\u003c/a\u003e\u003c/span\u003e \u003cspan class=\"image\"\u003e\u003ca href=\"https://github.com/fardjad/node-parse-my-command/actions\" class=\"image\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/fardjad/node-parse-my-command/test-and-release.yml?branch=main\" alt=\"test-and-release Workflow Status\" /\u003e\u003c/a\u003e\u003c/span\u003e\n\n\u003c/div\u003e\n\n\u003chr /\u003e\n\n[Commander.js](https://github.com/tj/commander.js) doesn't support parsing\n`argv` without executing the command. This module provides a workaround for that.\n\n## Installation\n\n```bash\nnpm install --save parse-my-command\n```\n\n## Usage\n\n```js\nimport { Command } from \"commander\";\nimport { partialParse } from \"parse-my-command\";\n\nconst rootCommand = new Command(\"root\")\n  .requiredOption(\"-a, --option-a \u003cvalue\u003e\", \"option a\")\n  .action(() =\u003e {\n    throw new Error(\"This should never get called\");\n  });\n\nconst childCommand = rootCommand\n  .command(\"child\")\n  .requiredOption(\"-b, --option-b \u003cvalue\u003e\", \"option b\")\n  .requiredOption(\"-c, --option-c \u003cvalue\u003e\", \"option c\")\n  .action(() =\u003e {\n    throw new Error(\"This should never get called\");\n  });\n\nconst argv = [\"node\", \"index.mjs\", \"-a\", \"value1\", \"child\", \"-b\", \"value2\"];\n\nconst {\n  matchedCommand,\n  providedOptions,\n  missingOptions,\n  providedOptionsSources,\n} = partialParse(rootCommand, argv);\n\nconsole.log(matchedCommand.name()); // child\nconsole.log(providedOptions.get(childCommand)); // { optionB: 'value2' }\nconsole.log(missingOptions.get(childCommand)); // Set(1) { 'optionC' }\nconsole.log(providedOptionsSources.get(childCommand)); // Map(1) { 'optionB' =\u003e 'cli' }\n```\n\nMore examples can be found in the [examples](/examples/) directory.\n\n## Error Handling\n\n`partialParse` throws in the following cases:\n\n1. In all cases where your `Command` with the\n   [default `exitCallback`](https://github.com/tj/commander.js#override-exit-and-output-handling)\n   would throw an error (e.g. when displaying help)\n2. In all cases where your command would throw an error before an action is\n   executed except for when a required `Option` (not to be confused with an\n   `Argument`) is missing (missing options are returned in the result object\n   instead).\n\n## How It Works and Limitations\n\nThis module works by creating a (best-effort) clone of the command and its\nsubcommands, setting the actions to no-op functions, and then parsing the\n`argv` with the cloned instance. This approach might have some limitations:\n\n1. The implementation might break if Commander.js changes its internals\n2. Custom argument and option processors are assumed to be pure functions\n3. Hook listeners attached to the commands will be ignored\n4. Some edge cases might not be handled correctly (please feel free to open an\n   issue/PR in case you find any)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffardjad%2Fnode-parse-my-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffardjad%2Fnode-parse-my-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffardjad%2Fnode-parse-my-command/lists"}