Skip to main content
Module

x/cliffy/command/upgrade/_check_version.ts

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Latest
File
import { bold, yellow } from "../deps.ts";import { Command } from "../command.ts";
/** Check if new version is available and add hint to version. */// deno-lint-ignore no-explicit-anyexport async function checkVersion(cmd: Command<any>): Promise<void> { const mainCommand = cmd.getMainCommand(); const upgradeCommand = mainCommand.getCommand("upgrade");
if (!isUpgradeCommand(upgradeCommand)) { return; } const latestVersion = await upgradeCommand.getLatestVersion(); const currentVersion = mainCommand.getVersion();
if (currentVersion === latestVersion) { return; } const versionHelpText = `(New version available: ${latestVersion}. Run '${mainCommand.getName()} upgrade' to upgrade to the latest version!)`;
mainCommand.version(`${currentVersion} ${bold(yellow(versionHelpText))}`);}
function isUpgradeCommand(command: unknown): command is UpgradeCommandImpl { return command instanceof Command && "getLatestVersion" in command;}
interface UpgradeCommandImpl { getLatestVersion(): Promise<string>;}