/** * Check for and install updates. */ import chalk from "@oh-my-pi/pi-utils/chalk"; import { Command, Flags } from "@oh-my-pi/pi-utils/cli"; import { updateHelp as commandHelp } from "../cli/command-help"; import * as pluginCli from "../cli/plugin-cli"; import * as updateCli from "../cli/update-cli"; import { CliUsageError } from "../cli/usage-error"; import { initTheme } from "@oh-my-pi/pi-tui/theme"; export default class Update extends Command { static description = commandHelp.description; static flags = { force: Flags.boolean({ char: "f", description: "Force update", default: false }), check: Flags.boolean({ char: "c", description: "Check for updates without installing", default: false }), plugins: Flags.boolean({ char: "l", description: "Update installed plugins", default: false }), canary: Flags.boolean({ description: "Switch to the canary channel and update", default: false }), stable: Flags.boolean({ description: "Switch back to the stable channel", default: false }), }; static examples = ["omp update", "omp update --check", "omp update --canary"]; async run(): Promise { const { flags } = await this.parse(Update); await initTheme(); if (flags.canary && flags.stable) throw new CliUsageError("--canary and --stable are mutually exclusive"); if (flags.plugins) { await pluginCli.runPluginCommand({ action: "upgrade", args: [], flags: flags.check ? { dryRun: true } : {} }); } else { try { await updateCli.runUpdateCommand({ force: flags.force, check: flags.check, channel: flags.canary ? "canary" : flags.stable ? "stable" : undefined, }); } catch (err) { console.error(chalk.red(err instanceof Error ? err.message : String(err))); process.exit(1); } } } }