Crust logoCrust

Version

Add a root-only version flag.

Usage

cli.ts
import { Crust } from "@crustjs/core";
import { version } from "@crustjs/extensions";

const app = new Crust("my-cli", { version: "1.2.3" }).extend(version()).action(() => {});

await app.execute();
$ my-cli --version
my-cli v1.2.3

version() owns the root-only --version and -v flag. It writes through the invocation's stdout callback and finishes before the Command Action.

API

version();
version("1.2.3");
version(() => process.env.APP_VERSION ?? "dev");

Without an explicit value, version() requires root version metadata. A value typed string | undefined still requires that metadata, as described by RootMetaKey. An explicit value affects only the version flag and does not populate root metadata for completion, skills, or other Extensions.

Options

version("1.2.3", { format: "plain" });
// $ my-cli --version
// 1.2.3
OptionTypeDefault
format"plain" | ((version: string, context: ExtensionContext) => string)`${rootName} v${version}`

A format function returns the line written for the flag. An explicit value may be a string or a function that resolves a string when the flag is handled.

On this page