commander-version
A wrapper for Commander that automatically sets the version based on your package.json
Last updated 4 years ago by bconnorwhite .
MIT · Repository · Original npm · Tarball · package.json
$ gnpm install commander-version 
SYNC missed versions from official npm registry.

commander-version

npm typescript GitHub stars Twitter Follow

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

Installation

yarn add commander-version
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:

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.

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:

import commander from "commander-version";

type MyType = commander.Command;

Commander

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

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

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

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

Dependenciesdependencies


Dev DependenciesDavid


License license

MIT

Related Packages

Current Tags

  • 3.0.0                                ...           latest (2 years ago)

5 Versions

  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |