UNPKG

@pompeii-labs/cli

Version:

Magma CLI

78 lines (76 loc) 2.53 kB
import { Command } from "commander"; import chalk from "chalk"; import { initCommand } from "./commands/init.js"; import { deployCommand } from "./commands/deploy.js"; import { welcomeCommand } from "./commands/welcome.js"; import { stopCommand } from "./commands/stop.js"; import { loginCommand } from "./commands/login.js"; import { runCommand } from "./commands/run.js"; import { logsCommand } from "./commands/logs.js"; import { connectCommand } from "./commands/connect.js"; import { linkCommand } from "./commands/link.js"; import { switchCommand } from "./commands/switch.js"; import { updateCommand } from "./commands/update.js"; import { cloneCommand } from "./commands/clone.js"; import { saveCommand } from "./commands/save.js"; import { execSync } from "child_process"; import { magma } from "./ui.js"; import { envCommand } from "./commands/env.js"; import { templateCommand } from "./commands/template.js"; const description = `Create, deploy, and run agents on the cloud. To get started, run "magma welcome" to see a quickstart guide.`; function getPublishedVersion() { try { const npmInfo = execSync("npm view @pompeii-labs/cli version", { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"] // Suppress npm error output }); return npmInfo.trim(); } catch (error) { console.log("Error getting published version:", error); return "0.0.0"; } } function run() { const program = new Command(); const version = "1.2.0"; const latestVersion = getPublishedVersion(); if (version !== latestVersion) { console.log( chalk.yellow( `You are using an outdated version of Magma. Please update to the latest version by running ${magma("magma update")} to continue.` ) ); } program.name("magma").description(description).version(version); initCommand(program); deployCommand(program); stopCommand(program); runCommand(program); welcomeCommand(program); loginCommand(program); logsCommand(program); connectCommand(program); linkCommand(program); switchCommand(program); updateCommand(program); cloneCommand(program); saveCommand(program); envCommand(program); templateCommand(program); program.allowUnknownOption(true); program.commands.forEach((command) => { command.allowUnknownOption(true); if (command.commands?.length) { command.commands.forEach((subCommand) => { subCommand.allowUnknownOption(true); }); } }); program.parse(); } export { getPublishedVersion, run };