UNPKG

@pompeii-labs/cli

Version:

Magma CLI

41 lines (40 loc) 1.29 kB
import chalk from "chalk"; import path from "path"; import fs from "fs"; import { stopAgent } from "../api.js"; import { isAuthenticated } from "../auth.js"; import { magma } from "../ui.js"; function stopCommand(program) { program.command("stop").description("Stop a running Magma agent").option("-p, --project <path>", "Path to the project directory", ".").action(async (options) => { if (!isAuthenticated()) { console.log( chalk.white(`Not authenticated with Magma. Please run ${magma("magma login")}`) ); process.exit(1); } try { await stop(options); console.log(chalk.green(` \u{1F30B} Successfully stopped agent! `)); } catch (error) { console.error(chalk.red(` \u274C Failed to stop agent: ${error.message}`)); process.exit(1); } }); } async function stop(options) { const projectDir = path.resolve(options.project); const cacheDir = path.join(projectDir, ".magma", ".cache"); if (!fs.existsSync(cacheDir)) { throw new Error("No agent found in this directory. Have you deployed one?"); } const cache = JSON.parse(fs.readFileSync(cacheDir, "utf8")); const agentId = cache.id; console.log(chalk.yellow(`Stopping agent: ${agentId}...`)); await stopAgent(agentId); } export { stopCommand };