{"id":50813969,"url":"https://github.com/danielpza/commander-register","last_synced_at":"2026-06-13T07:33:44.147Z","repository":{"id":350822321,"uuid":"1208128921","full_name":"danielpza/commander-register","owner":"danielpza","description":"Extends commander.js with a fastify-like plugin `register` api","archived":false,"fork":false,"pushed_at":"2026-04-12T08:26:19.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-12T10:16:15.933Z","etag":null,"topics":["commander","commanderjs","javascript","node","nodejs","plugin","register"],"latest_commit_sha":null,"homepage":"","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/danielpza.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":"2026-04-11T21:24:28.000Z","updated_at":"2026-04-12T08:26:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/danielpza/commander-register","commit_stats":null,"previous_names":["danielpza/commander-register"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/danielpza/commander-register","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpza%2Fcommander-register","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpza%2Fcommander-register/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpza%2Fcommander-register/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpza%2Fcommander-register/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielpza","download_url":"https://codeload.github.com/danielpza/commander-register/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpza%2Fcommander-register/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34276501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"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":["commander","commanderjs","javascript","node","nodejs","plugin","register"],"created_at":"2026-06-13T07:33:43.453Z","updated_at":"2026-06-13T07:33:44.123Z","avatar_url":"https://github.com/danielpza.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# commander-register\n\nExtends [commander.js](https://github.com/tj/commander.js) with a fastify-like plugin `register` api.\n\nFeatures:\n\n- **type safety:** plugins that extend the command instance are supported.\n- **lightweight:** no dependencies needed.\n- **familiar:** similar api to fastify's register api\n\nExample:\n\n```js\nimport { Command } from \"commander\";\nimport \"commander-register/patch\";\n\nnew Command()\n  .option(\"-c, --compress\")\n  .command(\"sub-command\")\n  .register(prettyErrors)\n  .register(setMeta)\n  .register(logger)\n  .action(() =\u003e {\n    // noop\n  })\n  .parse();\n```\n\nSee [./examples/plugins.mjs](./examples/plugins.mjs)\n\n## Installation\n\n```sh\nnpm install commander-register\npnpm install commander-register\nyarn add commander-register\n```\n\n## Setup\n\nImport `commander-register/patch` once at the entry point of your app. It patches `Command.prototype` with the `register` method. All `Command` instances (including those created via `createCommand`) will have `register` available.\n\n```js\nimport \"commander-register/patch\";\nimport { Command, program } from \"commander\";\n\nprogram.register(prettyErrorsPlugin).parse();\n\nconst command = new Command();\ncommand.register(loggerPlugin);\n```\n\n### Applying the patch using `node --import`\n\nYou can also apply the patch globally using Node's `--import` flag:\n\n```sh\nnode --import commander-register/patch your-app.js\n```\n\n## Plugins\n\nUse `command.register(plugin)` to modify command behavior. `plugin` is a function that receives the `Command` object.\n\nExample:\n\n```js\nprogram.register(prettyErrors).parse();\n\nfunction prettyErrors(command) {\n  command.configureOutput({\n    /* snip */\n  });\n}\n```\n\n### Extending command instance with more functionality\n\nReturn the instance from the plugin to let TypeScript infer the newly added methods:\n\n```js\nprogram.register(helloWorldPlugin).helloWorld().parse();\n\nfunction helloWorldPlugin(command) {\n  return Object.assign(command, {\n    helloWorld() {\n      console.log(\"Hello World\");\n      return this;\n    },\n  });\n}\n```\n\n### defineCommanderPlugin\n\nUse the `defineCommanderPlugin` helper to ensure type safety when creating plugins:\n\n```js\nimport { defineCommanderPlugin } from \"commander-register\";\n\nexport const prettyErrors = defineCommanderPlugin((command) =\u003e {\n  command.configureOutput({\n    /* snip */\n  });\n});\n```\n\n## Resources\n\n- https://github.com/tj/commander.js/issues/2505 - Plugin API discussion in commander.js\n- https://github.com/tj/commander.js/pull/2503 - Pull request adding this plugin to commander.js codebase.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpza%2Fcommander-register","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielpza%2Fcommander-register","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpza%2Fcommander-register/lists"}