A wrapper for Commander that automatically sets the version based on your package.json
npm install commander-version> A wrapper for Commander that automatically sets the version based on your package.json.
``bash`
yarn add commander-version
`bash`
npm install commander-version
> 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.
##
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();
`
##
For creating types, the Commander namespace can also be imported:
`ts
import commander from "commander-version";
type MyType = commander.Command;
`
##
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("...")
// ...
``
- @bconnorwhite/module: Read your module's package.json without importing it
- commander: the complete solution for node.js command-line programs
- @bconnorwhite/bob: Bob is a toolkit for TypeScript projects
- @bconnorwhite/module: Read your module's package.json without importing it