Skip to main content

Version Information

One common requirement of CLI applications is to display their own current version. The version integration provides a built-in --version flag for Stricli applications, and registers a hook to provide a warning. It accepts the additional flag properties for an integration, but also has additional properties to control how the version information is displayed. The info object in the options is a copy of the now-deprecated versionInfo configuration object.

To enable this integration, you must provide either a static currentVersion string or a function getCurrentVersion which asynchronously returns the current version. For applications that are are either bundled or support importing from .json files, you can simply import the version from your package.json file and provide it as the currentVersion. For example:

import { buildApplication, version } from "@stricli/core";
import pkg from "./package.json";

// Directly, through the integration
export const app = buildApplication(
root,
{
name: pkg.name,
},
{
version: version({
brief: "Print the current version of the application",
alias: "v",
info: {
currentVersion: pkg.version,
},
}),
},
);

// Indirectly, through the application configuration
export const app = buildApplication(root, {
name: pkg.name,
versionInfo: {
currentVersion: pkg.version,
},
});

Update Warnings

Another related requirement is to warn users when their version is outdated and there is an updated version available. In the info object you can also specify a getLatestVersion function which optionally accepts currentVersion and returns the latest version of the application, if it is available. During the specified lifecycle hook, the integration will then compare the current version against the latest version and print a warning to stderr. Optionally a command can be provided (upgradeCommand) to customize the message if there is a simple way for end users to upgrade to the latest version.

The text of this warning can be controlled by the localization but will only be displayed when getLatestVersion is provided and the current version does not match the latest version.