# commander-version

> A wrapper for Commander that automatically sets the version based on your package.json

Latest version **3.0.0** (published 2022-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install commander-version
pnpm add commander-version
yarn add commander-version
bun add commander-version
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2022-11-26 |
| First published | 2020-09-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Connor White |
| Maintainers | bconnorwhite |
| Keywords | commander, version, set, package, json, pkg, plugin |

## Links

- npm: https://www.npmjs.com/package/commander-version
- Repository: https://github.com/bconnorwhite/commander-version
- Homepage: https://connorwhite.org/github/commander-version
- npm.io page: https://npm.io/package/commander-version

## Dependencies (2)

- [commander](https://npm.io/package/commander.md) ^7.2.0
- [@bconnorwhite/module](https://npm.io/package/@bconnorwhite/module.md) ^2.0.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.0.0 (latest) — 2022-11-26
- 2.0.0 — 2021-04-18
- 1.1.0 — 2020-09-14
- 1.0.1 — 2020-09-09
- 1.0.0 — 2020-09-09

## README

<div align="center">
  <h1>commander-version</h1>
  <a href="https://npmjs.com/package/commander-version">
    <img alt="npm" src="https://img.shields.io/npm/v/commander-version.svg">
  </a>
  <a href="https://github.com/bconnorwhite/commander-version">
    <img alt="typescript" src="https://img.shields.io/github/languages/top/bconnorwhite/commander-version.svg">
  </a>
  <a href="https://github.com/bconnorwhite/commander-version">
    <img alt="GitHub stars" src="https://img.shields.io/github/stars/bconnorwhite/commander-version?label=Stars%20Appreciated%21&style=social">
  </a>
  <a href="https://twitter.com/bconnorwhite">
    <img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/bconnorwhite.svg?label=%40bconnorwhite&style=social">
  </a>
</div>

<br />

> A wrapper for Commander that automatically sets the version based on your package.json.

## Installation

```bash
yarn add commander-version
```

```bash
npm install commander-version
```

## API

### Default

> Note: also capitalizes 'help' and 'version' descriptions by default.

To set the version, import `program` the same as you would for Commander, just pass `__dirname` or `import.meta.url`:

```ts
import { program } from "commander-version";

program(__dirname) // Use `import.meta.url` for ESM
  .name("my-program")
  .description("...")
  // ...
  .parse();
```

This creates a new Command rather than using the global Command, which can cause issues.

##

### Flags and Description

You can also add flags or descriptions the same as with `program.version()`:

> Note: the default flags are set to "-v --version" to be inline with other programs, such as Node.js.

```ts
import { program } from "commander-version";

// To set flags back to the Commander default of "-V --version", for example:

program(__dirname, "-V --version", "custom version description")
  .name("my-program")
  .description("...")
  // ...
  .parse();
```

##

### Types

For creating types, the Commander namespace can also be imported:

```ts
import commander from "commander-version";

type MyType = commander.Command;
```

##

### Commander

For convenience, Commander and createCommand can also be used without setting the version:

```ts
import commander, { createCommand } from "commander-version";

new commander.Command("my-command")
  .description("...")
  // ...

const myCommand = createCommand("my-command")
  .description("...")
  // ...
```

<br />

<h2>Dependencies<img align="right" alt="dependencies" src="https://img.shields.io/david/bconnorwhite/commander-version.svg"></h2>

- [@bconnorwhite/module](https://www.npmjs.com/package/@bconnorwhite/module): Read your module's package.json without importing it
- [commander](https://www.npmjs.com/package/commander): the complete solution for node.js command-line programs

<br />

<h2>Dev Dependencies<img align="right" alt="David" src="https://img.shields.io/david/dev/bconnorwhite/commander-version.svg"></h2>

- [@bconnorwhite/bob](https://www.npmjs.com/package/@bconnorwhite/bob): Bob is a toolkit for TypeScript projects

<br />

<h2>License <img align="right" alt="license" src="https://img.shields.io/npm/l/commander-version.svg"></h2>

[MIT](https://opensource.org/licenses/MIT)

## Related Packages

- [@bconnorwhite/module](https://www.npmjs.com/package/@bconnorwhite/module): Read your module's package.json without importing it

---
_Source: https://npm.io/package/commander-version · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
