{"id":17050462,"url":"https://github.com/eush77/help-version","last_synced_at":"2025-04-12T16:24:02.915Z","repository":{"id":57262677,"uuid":"36123516","full_name":"eush77/help-version","owner":"eush77","description":"Easily handle --help and --version arguments in your CLI application","archived":false,"fork":false,"pushed_at":"2016-06-16T18:49:36.000Z","size":20,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T21:47:38.167Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/eush77.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}},"created_at":"2015-05-23T13:05:13.000Z","updated_at":"2023-02-17T11:32:51.000Z","dependencies_parsed_at":"2022-09-02T05:22:38.120Z","dependency_job_id":null,"html_url":"https://github.com/eush77/help-version","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eush77%2Fhelp-version","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eush77%2Fhelp-version/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eush77%2Fhelp-version/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eush77%2Fhelp-version/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eush77","download_url":"https://codeload.github.com/eush77/help-version/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248594532,"owners_count":21130380,"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-10-14T09:56:56.117Z","updated_at":"2025-04-12T16:24:02.892Z","avatar_url":"https://github.com/eush77.png","language":"JavaScript","readme":"[![npm](https://nodei.co/npm/help-version.png)](https://nodei.co/npm/help-version/)\n\n# help-version\n\n[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david]\n\nAnything you wanted to do with `--help` and `--version`:\n\n- checks these arguments in `process.argv`, so you don't have to;\n- extracts `version` from your `package.json` file;\n- returns functions that give you both `--help` and `--version`, in case you need to handle them differently;\n- returns the function that prints `--help` and exits with the given code;\n- highly configurable: you can set `process.argv`, `stdout` and `stderr` streams, and even `process.exit` function — this means testing won't be a problem.\n\n[travis]: https://travis-ci.org/eush77/help-version\n[travis-badge]: https://travis-ci.org/eush77/help-version.svg\n[david]: https://david-dm.org/eush77/help-version\n[david-badge]: https://david-dm.org/eush77/help-version.png\n\n## Example\n\n```js\n#!/usr/bin/env node\n\nvar Cli = require('help-version');\n\nvar cli = Cli('Usage:  my-cat [file]');\n\ncli.version()\n//=\u003e \"v0.1.0\"\n\nif (process.argv.length != 3) {\n  // Show help and exit with code 1.\n  cli.help(1);\n}\n\nfs.createReadStream(process.argv[2])\n  .pipe(process.stdout);\n```\n\nCatches `--help` and `--version` automatically.\n\n```\n$ ./cat.js --help\nUsage:  my-cat [file]\n$ ./cat.js --version\nv0.1.0\n$ ./cat.js file.txt\ncontents of file.txt\n```\n\n## API\n\n### `cli = Cli(helpText, [opts])`\n\n- `helpText` {String | Function} — help text to print on `--help`, or function to produce it.\n\nChecks `opts.argv` for `--help` or `--version`.\n\n1. If `--help` is found, prints `helpText` to `opts.stdout` and calls `opts.exit`.\n\n2. If `--version` is found, prints app version (determined from the `version` field from your local `package.json`) to `opts.stdout` and calls `opts.exit`.\n\nReturns object with two (bound) methods: `cli.help([code], [stream])` and `cli.version([code], [stream])`.\n\n| Option         | Default                 |\n| :------------: | :---------------------: |\n| `argv`         | `process.argv.slice(2)` |\n| `exit([code])` | `process.exit`          |\n| `stdout`       | `process.stdout`        |\n| `stderr`       | `process.stderr`        |\n\n### `cli.help([code], [stream])`\n\nWith no arguments, returns the help string.\n\nWith one or two arguments, writes it to `stream` instead and exits (via `opts.exit`) with `code`. `stream` defaults to `opts.stdout` if `code==0` and `opts.stderr` otherwise.\n\n### `cli.version([code], [stream])`\n\nWith no arguments, returns the version string.\n\nWith one or two arguments, writes it to the `stream` instead and exits (via `opts.exit`) with `code`. `stream` defaults to `opts.stdout` if `code==0` and `opts.stderr` otherwise.\n\n## Install\n\n```\nnpm install help-version\n```\n\n## License\n\nMIT\n","funding_links":[],"categories":["Modules","模块"],"sub_categories":["CLI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feush77%2Fhelp-version","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feush77%2Fhelp-version","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feush77%2Fhelp-version/lists"}